Error with nullable ref types with netcoreapp3.1
See original GitHub issueIssue Description
Issues found with nullable ref types when TargetFramework is netcoreapp3.1
Steps to Reproduce
- Create a new .NET Core console app
- Add the following code to Program.cs:
string? testString = "Hi";
Console.WriteLine(testString);
- Add
<Nullable>enable</Nullable>
to the project file. - Build - Note: Builds and runs fine.
- Open in vscode
- Build
Expected Behavior
No error shown
Actual Behavior
- Red underline on the “?” with an error: Feature ‘nullable reference types’ is not available in C# 7.3. Please use language version 8.0 or greater.
- The project is defaulted to netcoreapp3.1. If I try the same steps, but set the TargetFramework to netcoreapp3.0, there is no issue.
Logs
OmniSharp log
C# log
Environment information
VSCode version: 1.40.2 C# Extension: 1.21.8
Mono Information
OmniSharp using built-in monoDotnet Information
.NET Core SDK (reflecting any global.json): Version: 3.1.100 Commit: cd82f021f4Runtime Environment: OS Name: centos OS Version: 7 OS Platform: Linux RID: centos.7-x64 Base Path: /usr/share/dotnet/sdk/3.1.100/
Host (useful for support): Version: 3.1.0 Commit: 157910edee
.NET Core SDKs installed: 3.0.101 [/usr/share/dotnet/sdk] 3.1.100 [/usr/share/dotnet/sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.App 3.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
Visual Studio Code Extensions
Extension | Author | Version |
---|---|---|
csharp | ms-vscode | 1.21.8 |
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:6 (1 by maintainers)
Top GitHub Comments
Thanks for the report. There was a bug in the C# targets in the lead up to the full release of .NET Core 3.1 where the implicit default LangVersion was 7.3 instead of 8.0. This might be the source of the issue. I just tried this with the .NET 5 preview SDK and latest OmniSharp and everything worked as expected. If you don’t see this working, please let us know and we can take a look.
@dseefeld I was able to get the “red underline” to go away in my netcoreapp3.1 project
In the .csproj I added <LangVersion /> to the <PropertyGroup />
Configure language version
Not sure if that is a permanent solution but at least the warning disappeared Could probably set this to “3.1” also to get the same effect