dotnet-csharp-nullable-reference-types

Guides enabling and annotating C# nullable reference types with migration strategies and attribute patterns.

Updated May 22, 2026
One-click install
npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill dotnet-csharp-nullable-reference-types-viniciuscs84
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-csharp-nullable-reference-types
Source: https://github.com/viniciuscs84/sdd-toolkit/tree/main/skills/dotnet-csharp-nullable-reference-types
Command: npx skills add https://github.com/viniciuscs84/sdd-toolkit --skill dotnet-csharp-nullable-reference-types-viniciuscs84

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? C# codebases without proper nullable reference type (NRT) annotations suffer from NullReferenceException bugs and compiler warnings that AI agents often silence incorrectly with the null-forgiving operator. This Skill provides the annotation patterns, attributes, and migration strategies needed to adopt NRT correctly. ## Core Features & Use Cases - NRT Enablement & Migration: Enable <Nullable>enable</Nullable> project-wide or per-file with #nullable directives, including an incremental migration strategy for large legacy codebases. - Nullability Attributes: Apply [NotNullWhen], [MemberNotNull], [NotNullIfNotNull], [DoesNotReturn], and related attributes from System.Diagnostics.CodeAnalysis to express contracts the compiler cannot infer. - Agent Gotcha Prevention: Avoid the five most common AI agent mistakes, such as abusing the ! operator, ignoring CS8602 warnings, and breaking nullable contracts on interface implementations. - Use Case: When migrating a legacy .NET Framework codebase to net8.0, use this Skill to enable NRT incrementally, annotate Try-pattern methods correctly, and configure EF Core entities so required and optional columns map to non-nullable and nullable properties. ## Quick Start Ask the AI to enable nullable reference types in your .NET project and fix the resulting warnings file by file using proper annotations instead of the null-forgiving operator.

Frequently Asked Questions about dotnet-csharp-nullable-reference-types

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I enable nullable reference types in a C# project?

Add <Nullable>enable</Nullable> to a PropertyGroup in your .csproj or Directory.Build.props file. For gradual adoption, use #nullable enable at the top of individual files instead of enabling it project-wide.

How to migrate a legacy .NET codebase to nullable reference types?

Enable NRT project-wide, then add #nullable disable to every existing file. Remove the directive file by file, fixing warnings as you go, and track progress by counting remaining #nullable disable directives.

Does the target framework version enable nullable reference types automatically?

No. The TFM does not enforce NRT; the <Nullable> MSBuild property does. New net6.0+ templates include it by default, but legacy projects upgraded to net8.0 may still have it disabled.

Why is using the null-forgiving operator in C# considered bad practice?

The ! operator suppresses compiler warnings without fixing the underlying null risk, so a null value still causes a NullReferenceException at runtime. It is only acceptable when you have knowledge the compiler cannot verify, such as EF Core navigation properties.

What is the difference between int? and string? in C#?

int? is Nullable<int>, a distinct runtime type that has always existed. string? is a compile-time NRT annotation only; typeof(string?) equals typeof(string), so there is no runtime type change.

How does EF Core use nullable reference type annotations?

EF Core maps non-nullable reference properties to NOT NULL columns and nullable properties to NULL columns. For required navigation properties, = null! is an accepted use of the null-forgiving operator because EF guarantees initialization.