question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error with nullable ref types with netcoreapp3.1

See original GitHub issue

Issue Description

Issues found with nullable ref types when TargetFramework is netcoreapp3.1

Steps to Reproduce

  1. Create a new .NET Core console app
  2. Add the following code to Program.cs:
            string? testString  = "Hi";
            Console.WriteLine(testString);
  1. Add <Nullable>enable</Nullable> to the project file.
  2. Build - Note: Builds and runs fine.
  3. Open in vscode
  4. 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

Post the output from Output-->OmniSharp log here

C# log

Post the output from Output-->C# here

Environment information

VSCode version: 1.40.2 C# Extension: 1.21.8

Mono Information OmniSharp using built-in mono
Dotnet Information .NET Core SDK (reflecting any global.json): Version: 3.1.100 Commit: cd82f021f4

Runtime 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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
cartermpcommented, Mar 26, 2020

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.

1reaction
elfaraorigocommented, Dec 17, 2019

@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 />

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <LangVersion>latest</LangVersion>
  </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

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to treat ALL C# 8 nullable reference warnings as errors?
It is now possible to treat all nullable-related warnings as errors without explicitly specifying them all. To achieve this, you have to set ......
Read more >
Try out Nullable Reference Types - Microsoft Developer Blogs
Try out Nullable Reference Types. With the release of .NET Core 3.0 Preview 7, C# 8.0 is considered "feature complete".
Read more >
Nullable feature of C# 8 is not working - Visual Studio Feedback
I have created a new Empy ASP.NET Core 3.0-preview7 app, switched to C# 8 enabled Nullable. My csproj is: <Project Sdk="Microsoft.NET.
Read more >
C# 8: Nullable Reference Types - Meziantou's blog
#Why to use nullable reference types? C# 8 brings a new feature to solve the one billion-dollar mistake . The compiler will help...
Read more >
How to turn on C# 8 Nullable Reference Types
What if I always ignore compiler's warnings? Ha! No worries, you can always make compiler to treat warnings as errors. To do so,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found