Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug Assembly-CSharp.csproj created with <LangVersion>latest</LangVersion>, not currently used in Unity

Discussion in 'Editor & General Support' started by idchlife, Aug 21, 2020.

  1. idchlife

    idchlife

    Joined:
    Jul 25, 2016
    Posts:
    15
    I was wondering, why Unity screamed at me with

    Code (CSharp):
    1. error CS0136: A local or parameter named 't' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
    2.  
    But my editor had nothing to say about this.
    I searched internet for the problems with my IDEs (VSCode, Visual Studio For Mac)

    At the end I discovered that since C# 8 version this error is no longer an error, and it's possible to code that way.

    My IDEs used "latest" version of language available for my system, which happened to be C# 8

    But Unity supports C# 7

    I found that the culprit is Assembly-CSharp.csproj file, which has line about using latest C# version available:

    <LangVersion>latest</LangVersion>

    I suspect this should be fixed from Unity's side? To force specify C# version which Unity supports and uses right now.

    To fix this - manually change version to 7.0 inside Assembly-CSharp.csproj file, like this:

    <LangVersion>7.0</LangVersion>
     
    omg_peter likes this.
  2. idchlife

    idchlife

    Joined:
    Jul 25, 2016
    Posts:
    15
    Didn't anyone else experience this?

    I am constantly suffer from errors I don't see in editor and some not even in Unity (syntax warnings), due to language versions mismatch.

    Example: I had Object not set to instance error due to lack of short list initialization syntax:

    List<Item> items = {
    item,
    item
    };

    I spent whole day catching this bug before I thought - hey.... Maybe the syntax doesn't work?...