dotnet-csharp-nullable-reference-types

Enable and manage nullable reference types in C# projects.

71|10|Updated Feb 11, 2026
One-click install
npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-csharp-nullable-reference-types-wshaddix
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-csharp-nullable-reference-types
Source: https://github.com/wshaddix/dotnet-skills/tree/main/skills/dotnet-csharp-nullable-reference-types
Command: npx skills add https://github.com/wshaddix/dotnet-skills --skill dotnet-csharp-nullable-reference-types-wshaddix

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps developers understand and correctly implement C# nullable reference types (NRT), preventing null reference exceptions and improving code reliability, especially when migrating legacy codebases.

Core Features & Use Cases

  • NRT Fundamentals: Explains annotation strategies, defaults by Target Framework Moniker (TFM), and project-wide/per-file enabling.
  • Migration Guidance: Provides a step-by-step strategy for incrementally enabling NRT in large projects.
  • Common Pitfalls: Highlights frequent mistakes made by AI agents and developers, such as incorrect use of the null-forgiving operator (!) and ignoring compiler warnings.
  • Attribute Usage: Details essential attributes like [NotNullWhen], [MemberNotNull], and [AllowNull] for precise nullability contracts.
  • Use Case: Migrating an older .NET Framework application to .NET 8 and want to leverage NRT to catch potential null issues early in the development cycle.

Quick Start

Enable nullable reference types project-wide by adding <Nullable>enable</Nullable> to your project file.

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?▼

To enable nullable reference types (NRT) in a C# project, add the <Nullable>enable</Nullable> property to your project file. This allows the compiler to perform null-state analysis and warn you about potential null reference exceptions.

What is the best way to migrate a legacy codebase to nullable reference types?▼

The best way to migrate a legacy codebase to nullable reference types is to use an incremental, step-by-step strategy. This Skill provides migration guidance that helps you progressively enable NRT across large projects without breaking existing functionality.

When should I use attributes like [NotNullWhen] and [MemberNotNull] in C#?▼

You should use attributes like [NotNullWhen] and [MemberNotNull] in C# to define precise nullability contracts. They inform the compiler's null-state analysis about method behaviors, preventing false warnings and ensuring robust null checking.

Why am I getting null state warnings after enabling nullable reference types?▼

Null state warnings after enabling nullable reference types usually occur because the compiler detects potential null values. Common pitfalls include ignoring compiler warnings or incorrectly using the null-forgiving operator (!) to suppress them instead of fixing the underlying null issue.

Can I enable nullable reference types on a per-file basis in C#?▼

Yes, you can enable nullable reference types on a per-file basis in C#. While adding <Nullable>enable</Nullable> to your project file applies it project-wide, you can also use directives within individual files to control NRT annotations locally.

What are common mistakes when using the null-forgiving operator in C#?▼

A common mistake when using the null-forgiving operator (!) in C# is applying it to silence compiler warnings without actually verifying null safety. This defeats the purpose of nullable reference types and can hide potential null reference exceptions in your code.