Enabling nullable types makes no difference

Viewed 946

I had some issues with enabling non-nullable reference types. Not sure if it's an actual issue or if it's me that isn't keeping up with the latest naming / setup of this.

This is my current setup (using VS Code):

Dotnet version: 3.0.100-preview6-012264
Omnisharp: 1.20.0

I noticed that the flag for enabling nullable has changed multiple times but as I could see in documentation, and on the internet, latest seemed to be <Nullable/> which I enabled in all (both main web project shown below and in my .NET Standard 2.0 class libs):

<Project Sdk="Microsoft.NET.Sdk.Web">

  ...

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <LangVersion>8.0</LangVersion>
    <Nullable>enable</Nullable>
    <WarningsAsErrors>CS8600;CS8602;CS8603</WarningsAsErrors>
  </PropertyGroup>

</Project>

If I use #nullable enable in the file I'm testing, I see that the IntelliSense switches directly to, what seems to be, the right alerts. Adding this in the file will also make the build fail (which is the behavior I'm seeking).

What am I missing here to get this working on the project level?

1 Answers

To summarize the discussion above:

The naming of this currently differs between omnisharp (vs code) and when using Visual Studio it seems. So the MS documentation, which specifies <Nullable> is not applicable. For omnisharp / vs code <NullableContextOptions>enable</NullableContextOptions> needs to be used instead (until omnisharp has been updated).

Related