NotNullMigration.Analyzer 0.1.0

dotnet add package NotNullMigration.Analyzer --version 0.1.0
                    
NuGet\Install-Package NotNullMigration.Analyzer -Version 0.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NotNullMigration.Analyzer" Version="0.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NotNullMigration.Analyzer" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="NotNullMigration.Analyzer">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NotNullMigration.Analyzer --version 0.1.0
                    
#r "nuget: NotNullMigration.Analyzer, 0.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NotNullMigration.Analyzer@0.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NotNullMigration.Analyzer&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=NotNullMigration.Analyzer&version=0.1.0
                    
Install as a Cake Tool

NotNullMigration.Analyzer

NuGet Build License: MIT

A Roslyn analyzer that helps migrate your C# projects to nullable-enabled (<Nullable>enable</Nullable>) by detecting nullable properties and fields that are only ever assigned non-nullable values.

Installation

dotnet add package NotNullMigration.Analyzer

Example

The analyzer detects nullable members that can safely be made non-nullable:

// Before — NOTNULL001: 'Name' is declared nullable but is only assigned non-nullable values
public class User
{
    public string? Name { get; set; }

    public User(string name)
    {
        Name = name;
    }

    public void UpdateName(string newName)
    {
        Name = newName;
    }
}

Apply the code fix to remove the unnecessary ?:

// After — no diagnostic
public class User
{
    public string Name { get; set; }

    public User(string name)
    {
        Name = name;
    }

    public void UpdateName(string newName)
    {
        Name = newName;
    }
}

Applying Code Fixes

IDE (Visual Studio / Rider / VS Code)

Hover over the warning and use the lightbulb (Quick Actions) to apply "Remove nullable annotation". You can also fix all occurrences at once via Fix All in Document / Project / Solution.

CLI

Use dotnet format to apply all fixes from the command line:

# Fix all NOTNULL001 warnings in the solution
dotnet format analyzers --diagnostics NOTNULL001 --severity warn

Rules

Rule ID Category Severity Description
NOTNULL001 Design Warning Nullable member can be made non-nullable

How It Works

The analyzer uses the Roslyn IOperation API to track all assignments to nullable properties and fields across the entire compilation. At CompilationEnd, it reports any member that was only assigned non-nullable values.

For interface properties, it aggregates across all implementations — reporting only when every implementation assigns exclusively non-nullable values.

For a detailed breakdown of all edge cases, see docs/architecture.md.

Configuration

You can change the severity or disable the rule in your .editorconfig:

[*.cs]
# Disable the rule
dotnet_diagnostic.NOTNULL001.severity = none

# Or change to error
dotnet_diagnostic.NOTNULL001.severity = error

Contributing

See CONTRIBUTING.md for build instructions and how to submit changes.

License

This project is licensed under the MIT License — see LICENSE for details.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0 34 3/10/2026