Proj0055: Enable nullability analysis for C#

In C# 8.0 and later, nullability analysis provides compile-time checks to ensure reference types are safely handled, helping to avoid NullReferenceException at runtime.

By leaving nullability analysis disabled or not defining it, reference types are considered nullable by default but without any compiler warnings when null is dereferenced or assigned incorrectly.

Migrating existing projects

Turning the feature on for an old codebase can immediately generate hundreds or thousands of compiler warnings. Fixing these blindly often leads to introducing subtle runtime bugs. In those cases we advise to follow one of the strategies advised by the .NET team.

Non-compliant

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

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
  </PropertyGroup>

</Project>

Or:

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

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>disable</Nullable>
  </PropertyGroup>

</Project>

Compliant

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

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>

Or:

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

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>annotations</Nullable>
  </PropertyGroup>

</Project>

Or:

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

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>warnings</Nullable>
  </PropertyGroup>

</Project>

Or supress it for stable code that should not be altered anymore:

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

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <NoWarn>Proj0055</NoWarn>
  </PropertyGroup>

</Project>