Visual Studio 2019 version 16.11.0 – error CS1576: The line number specified for #line directive is missing or invalid

I had the same error message with a .NET Core 5.0 web project in Visual Studio for Mac 8.10.11, after installing the Visual Studio for Mac 2022 preview with (as you guess) .NET Core 6.0 Preview. It might work on Windows too as mentioned in a now deleted answer.

The preview features as mentioned in @Failwyn’s answer, under Preferences → Preview Features did not include the option to use previews of the .NET SDK. Adding global.json as described in @Nenad’s answer did not work either.

Fortunately, I did have another .NET Core 5.0 project which did compile, so I was able to figure out the cause. Or at least the solution: this was to remove the <LangVersion> indications from the project file:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <LangVersion>latestmajor</LangVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <LangVersion>latestmajor</LangVersion>
  </PropertyGroup>

This surprises me, since it indicates the C# version, but apparently this influences the .NET SDK version as well.

enter image description here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)