3

I have a .NET 6 project. I want to retarget it to .NET 4.8. I did it from the project properties. I removed all instances of my code using newer language features. I have clean the solution also

However after doing it, I get an error while compiling

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

at line 1, from a file called CSC in my project folder (weird, CSC is the name of the compiler, and I have no such file). I am not using nullable types surely and this error is not correct IMO. What do I do?

EDIT: @RahulSharma's answer isn't valid. It doesn't work, produces another error.

demberto
  • 489
  • 5
  • 15
  • 1
    Check the .csproj file itself for this setting. – Lasse V. Karlsen Jan 31 '22 at 17:11
  • 3
    Does this answer your question? [C# compiler throws Language Version (LangVersion) reference error "Invalid 'nullable' value: 'Enable' for C# 7.3"](https://stackoverflow.com/questions/56637045/c-sharp-compiler-throws-language-version-langversion-reference-error-invalid) – Rahul Sharma Jan 31 '22 at 17:11
  • Note that the link Rahul suggested shows the correct project tags *in the question* rather than the answer. The answer is no longer correct. The question was asked prior to the release of 8.0. – madreflection Jan 31 '22 at 17:16
  • @madreflection Actually I did try that answer but still an autogenerated file is trying to import `System.Net.Http`. I think the real issue is the newer style `csproj` itself. The compiler probably assumes C# 8.0 when it sees the newer style `csproj` file. Also maybe somewhere at ``? – demberto Jan 31 '22 at 17:23
  • It's not. You can target `net48` and even `net20` with the new project style. I do it all the time. What you're probably dealing with is the fact that .NET 4.8 doesn't have a lot of stuff that .NET 6 does. You may have to add NuGet packages to get some of it, and the rest you can't use because it relies on newer framework or runtime support. – madreflection Jan 31 '22 at 17:28
  • That error is different, though, and you're getting it because you solved the first problem, which was getting the right language version for the feature you want to enable. On to the next problem. – madreflection Jan 31 '22 at 17:30

1 Answers1

2

This error is shown when your project settings reference the language version 7.3. I assume you can verify this by right-clicking your project & choose properties, build, advanced in VS. If the language version is shown as 7.3, you need to change this so it match the framework version you use. Howver you cannot change this in the VS dialogue, so you need to do this manually. Unload your project and open the project file as a file, and then add the <LangVersion>latest</LangVersion> in the <PropertyGroup> section. See the full documentation of language versions for each .NET framework version here

Kristian
  • 21
  • 4