C# compiler throws Language Version (LangVersion) reference error "Invalid 'nullable' value: 'Enable' for C# 7.3"

10,946

You should try <LangVersion>preview</LangVersion> as the error message suggests.

Share:
10,946
dnf
Author by

dnf

Updated on June 04, 2022

Comments

  • dnf
    dnf about 2 years

    I have solution with couple .NET Standard projects in all I wanted to enable c# 8 and nullable like below:

    <PropertyGroup>
        <TargetFramework>netstandard2.1</TargetFramework>
        <LangVersion>8.0</LangVersion>
        <Nullable>enable</Nullable>
      </PropertyGroup>
    

    The problem is that some projects are compiling fine and some have error:

    Invalid 'nullable' value: 'Enable' for C# 7.3. Please use language version 'preview' or greater

    I have Visual Studio 16.2 Preview 2 and .NET Core 3 Preview 6. Is this a bug in preview or I'm doing something wrong?

    • Panagiotis Kanavos
      Panagiotis Kanavos about 5 years
      No repro. I use 8.0 too. Do you have a global.json in those failing projects that points to an earlier SDK?
  • dnf
    dnf about 5 years
    With preview error message is the same
  • Panagiotis Kanavos
    Panagiotis Kanavos about 5 years
    preview is 8.0 at this point in time.
  • Avin Kavish
    Avin Kavish about 5 years
    It is not recognized as 8.0 till after release.
  • crakama
    crakama over 2 years
    If you right click on your project, navigate to "Properties" >> "Build" >> "Advanced" >> "Language Version" you will notice that visual studio does not provide UI to change the value, You may need to Navigate to the csproj file (by right click on each of your project in visual studio and select "Unload Project", to open up the csproj file) of all your projects under your solution and add <LangVersion>preview</LangVersion>. This settings will help your latest C# compiler determine the default language version based on your projects targets framework.