Agent skill

Csharp Nullable Reference Types

by Aaronontheweb in Aaronontheweb/dotnet-skills

Guidelines for introducing and using nullable reference types (NRT) and System.Diagnostics.CodeAnalysis nullable attributes in C / .NET codebases.

MITAuto-check passedBackend & APIs

Install Csharp Nullable Reference Types

skills CLI
$ npx skills add Aaronontheweb/dotnet-skills --skill csharp-nullable-reference-types -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install Aaronontheweb/dotnet-skills csharp-nullable-reference-types --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/Aaronontheweb/dotnet-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/csharp-nullable-reference-types .claude/skills/csharp-nullable-reference-types && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
csharp-nullable-reference-types
GitHub stars
1.2k
Used in
1 other repo
Token cost
~2.9k tokens
SKILL.md length
1,080 words
Files
3
Skills in repo
33
Repo updated
First seen
Licence
MIT

At a glance

Guidelines for introducing and using nullable reference types (NRT) and System.Diagnostics.CodeAnalysis nullable attributes in C / .NET codebases.

  • Works in 8 steps: Project — enable present; disable only… → Types — non-nullable for required… → Initialization — constructors, required… → …
  • Tasks that involve API design
  • SKILL.md covers When to Use, Core Goals, Core Nullability Model and Project Configuration, plus 5 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Csharp Nullable Reference Types is an agent skill from Aaronontheweb/dotnet-skills. Guidelines for introducing and using nullable reference types (NRT) and System.Diagnostics.CodeAnalysis nullable attributes in C / .NET codebases. Covers the nullability model, flow analysis, the null-forgiving operator, API design rules, the full attribute catalog (AllowNull, DisallowNull, MaybeNull, NotNull, NotNullWhen, MaybeNullWhen, NotNullIfNotNull, MemberNotNull, MemberNotNullWhen, DoesNotReturn, DoesNotReturnIf), the C 14 field keyword, incremental migration of legacy codebases, and a code-generation…

Its SKILL.md is about 2.9k tokens, which your agent loads only when the skill is triggered. The skill folder holds 2 other files (for example `nrt-migration-playbook-reference.md` and `nullable-attributes-reference.md`).

It sits in Backend & APIs, covering API design. It works with C# and .NET. The repository describes itself as: Claude Code skills and sub-agents for .NET Developers. The licence is MIT.

When your agent uses it

  • Tasks that involve API design

Example prompts

  • “Use the csharp-nullable-reference-types skill to guideline for introducing and using nullable reference types (NRT) and…”
  • “/csharp-nullable-reference-types”

Workflow steps

8 steps, taken from the first numbered list in SKILL.md.

  1. Project — enable present; disable only around unavoidable legacy code.
  2. Types — non-nullable for required params/returns/properties; T? only when null is valid and expected.
  3. Initialization — constructors, required + object initializers, field-backed lazy getters, or [MemberNotNull] helpers. Avoid null! except…
  4. Null checks — explicit guards at public boundaries; narrow with control flow, and extract a non-nullable helper only when it improves…
  5. Attributes — apply to express contracts the type system cannot express (see reference file).
  6. Interop — trust BCL/annotated libraries; add your own guards and attributes when wrapping unannotated APIs.
  7. Warnings — never ignore; fix design or add attributes rather than suppressing with ! or #pragma.
  8. Compatibility — for released libraries, review public nullability changes as potential source breaks and test nullable-enabled consumers.

What it can do on your machine

Read from SKILL.md and the folder at commit e426ed9. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are csharp and xml).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • learn.microsoft.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Csharp Nullable Reference Types loads about 2.9k tokens when it runs. Until then it costs about 140 tokens; SKILL.md has 1,080 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~140
When it runs · the whole SKILL.md, loaded when a task matches
~2.9k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from Aaronontheweb/dotnet-skills at commit e426ed9, republished under its MIT licence (© Aaronontheweb). 1,080 words, ~2,895 tokens.

Download SKILL.mdSave it as .claude/skills/csharp-nullable-reference-types/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
csharp-nullable-reference-types
description
Guidelines for introducing and using nullable reference types (NRT) and System.Diagnostics.CodeAnalysis nullable attributes in C# / .NET codebases. Covers the nullability model, flow analysis, the null-forgiving operator, API design rules, the full attribute catalog (AllowNull, DisallowNull, MaybeNull, NotNull, NotNullWhen, MaybeNullWhen, NotNullIfNotNull, MemberNotNull, MemberNotNullWhen, DoesNotReturn, DoesNotReturnIf), the C# 14 field keyword, incremental migration of legacy codebases, and a code-generation checklist.
version
1.0.0
tags
csharp, nullable, nrt, code-quality, api-design

C# Nullable Reference Types

When to Use

  • Introducing nullable reference types (NRT) into a codebase that has not yet adopted them
  • Writing or refactoring C# code that uses T? / nullable annotations
  • Annotating APIs with System.Diagnostics.CodeAnalysis nullable attributes
  • Designing public/internal APIs where nullability contracts matter
  • Wrapping unannotated or legacy APIs so downstream callers still benefit from NRT
  • Reviewing code for correct null-state analysis, guard helpers, and the field keyword

Core Goals

  • Prevent NullReferenceException at runtime by making null intent explicit in signatures.
  • Express contracts the type system cannot represent directly using the official nullable attributes.
  • Adopt NRT incrementally in legacy codebases without a big-bang rewrite.

Core Nullability Model

Non-nullable vs nullable
  • string — non-nullable reference. The compiler assumes instances are never null; assigning null or a maybe-null value produces a warning.
  • string? — nullable reference. The variable may be null; the compiler requires a null check before dereference.
csharp
string name = "Alice";
name = null;          // Warning: assigning null to non-nullable.

string? nickname = null;
Console.WriteLine(nickname.Length); // Warning: possible null dereference.
Null-state analysis (flow)

The compiler tracks whether a reference is definitely non-null or maybe null. Null checks and assignments update this state.

csharp
string? message = GetMessageOrNull();

if (message != null)
{
    // message is definitely non-null in this block.
    Console.WriteLine(message.Length);
}

// Outside the if, message is maybe null again.

Introduce explicit null checks (if (x != null), is not null, pattern matching) before dereferencing nullable values. Narrow nullability early and keep the non-null state alive. Null-conditional assignment (C# 14) lets you write customer?.Order = CreateOrder(); — the right side is evaluated only when the receiver is non-null.

Null-forgiving operator (!)

x! tells the compiler "treat x as non-null here." It affects analysis only, not runtime behavior.

  • Use ! only when a real invariant guarantees non-null and the compiler cannot see it.
  • Do not use ! as a general fix for warnings. Prefer refactoring control flow, adding attributes, or proper member initialization.
csharp
_customer = LoadCustomerFromOrm()!; // ORM guarantees this is not null in valid state.
Reorganize code before suppressing warnings

A successful guard clause or pattern match already creates a null-safe region in the current scope. Before adding !, make nullable values cross a checked boundary once and keep the remaining code non-nullable:

  • narrow early with a guard clause or pattern match;
  • copy nullable fields or properties to a local before checking, so repeated reads cannot change underneath the analysis;
  • when a method has complex control flow, optionally move the non-null path into a local function or private method with non-nullable parameters;
  • keep nullable handling at the boundary instead of spreading T?, repeated checks, or ! through the implementation.
csharp
public void Process(Order? order)
{
    if (order?.Customer is not { } customer)
    {
        return;
    }

    // The pattern match already proved that customer is non-null here.
    Console.WriteLine(customer.Name);
}

Do not extract a function solely to satisfy nullable analysis. Use an explicit non-nullable function boundary when it also simplifies a large or branching implementation. Use ! only when a real external invariant cannot be represented through control flow, signatures, or nullable-analysis attributes.

Project Configuration

Enable NRT for new code:

xml
<PropertyGroup>
  <Nullable>enable</Nullable>
</PropertyGroup>

For legacy codebases, enable incrementally with file-level directives (#nullable enable, #nullable disable, #nullable enable warnings, #nullable enable annotations). Treat CS86xx nullable warnings as important; consider TreatWarningsAsErrors or treating nullable warnings as errors in new projects.

See nrt-migration-playbook-reference.md for the full incremental-adoption strategy, #nullable directive reference, legacy interop, and known static-analysis limitations (arrays, default(struct)).

API Design Rules (Signatures)

These rules apply to public and internal APIs and to models.

Parameters — if null is not allowed, use a non-nullable type and add a runtime guard for public APIs:

csharp
public void SendEmail(string recipient)
{
    ArgumentNullException.ThrowIfNull(recipient);
    // Implementation
}

If null is allowed and meaningful, use T?, document how null is interpreted, and implement correct null behavior.

Return types — Customer when the method never returns null; Customer? when it can legitimately return null (callers must check, and the compiler enforces it).

csharp
public Customer GetRequiredCustomer(Guid id);  // Throws on failure.
public Customer? TryGetCustomer(Guid id);       // Returns null on failure.

Properties and fields — follow the same rules as parameters and return types. Non-nullable members must be initialized in constructors, via required properties with object initializers, via field-backed lazy properties, or via helpers annotated with [MemberNotNull].

csharp
public class Order
{
    public required string Id { get; init; }
    public required Customer Customer { get; init; }
    public string? Comment { get; init; } // Optional.
}

When contracts depend on input/output behavior, conditional behavior, or member initialization, apply the nullable attributes described in nullable-attributes-reference.md.

Show full SKILL.md (485 more words)Show less
Public API compatibility for libraries

Treat nullable annotations and nullable-analysis attributes as part of a shipped API contract. T and T? have the same CLR type, so annotation-only changes are generally binary compatible, but they can be source breaking by introducing warnings for nullable-enabled consumers. Those warnings often become build failures when consumers treat warnings as errors.

Review public nullability changes before release, especially:

  • weakening an output from T to T? or adding [MaybeNull];
  • tightening an input from T? to T or adding [DisallowNull];
  • changing generic constraints such as class?, class, or notnull;
  • changing annotations or attributes on virtual members, interfaces, delegates, and implementations, where mismatches produce compiler warnings.

Adding annotations to a previously nullable-oblivious API can create the same source-compatibility problems. Compare the annotated surface with the last released version, test a nullable-enabled consumer, and document or version intentional source-breaking changes according to the library's compatibility policy.

The field Keyword (C# 14 / .NET 10)

The field contextual keyword lets you write a property accessor body without declaring an explicit backing field. This is a primary NRT scenario (lazily-initialized properties) and the compiler performs a special null-resilience analysis so you do not get nuisance CS8618 in constructors:

csharp
public class C
{
    public C() { } // No warning: the getter is null-resilient.
    string Prop => field ??= GetPropValue();
}

See nullable-attributes-reference.md for the full field nullability rules (null-resilient vs non-resilient getters, the [field: AllowNull, MaybeNull] escape hatch, and setter/constructor analysis).

Reference Files

  • nullable-attributes-reference.md: The complete System.Diagnostics.CodeAnalysis attribute catalog — preconditions (AllowNull, DisallowNull), postconditions (MaybeNull, NotNull), conditional postconditions (NotNullWhen, MaybeNullWhen, NotNullIfNotNull), helper methods (MemberNotNull, MemberNotNullWhen), unreachable-code helpers (DoesNotReturn, DoesNotReturnIf), and the field keyword nullability rules. Each with intent, pattern, and agent rules.
  • nrt-migration-playbook-reference.md: Incremental adoption strategy, #nullable directive reference, legacy/unannotated API interop, polyfilling nullable attributes for older target frameworks (with tradeoffs and a confirm-before-adding decision process), known static-analysis limitations (arrays of non-nullable references, default(struct) with reference fields), warning handling, and the full generation checklist.

Generation Checklist (Summary)

  1. Project — <Nullable>enable</Nullable> present; disable only around unavoidable legacy code.
  2. Types — non-nullable for required params/returns/properties; T? only when null is valid and expected.
  3. Initialization — constructors, required + object initializers, field-backed lazy getters, or [MemberNotNull] helpers. Avoid null! except as a documented escape hatch.
  4. Null checks — explicit guards at public boundaries; narrow with control flow, and extract a non-nullable helper only when it improves complex code; ! only with a clear invariant.
  5. Attributes — apply to express contracts the type system cannot express (see reference file).
  6. Interop — trust BCL/annotated libraries; add your own guards and attributes when wrapping unannotated APIs.
  7. Warnings — never ignore; fix design or add attributes rather than suppressing with ! or #pragma.
  8. Compatibility — for released libraries, review public nullability changes as potential source breaks and test nullable-enabled consumers.

References

© Aaronontheweb, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files in skills/csharp-nullable-reference-types of Aaronontheweb/dotnet-skills.

  • SKILL.md
  • nrt-migration-playbook-reference.md
  • nullable-attributes-reference.md

Open the folder on GitHubat commit e426ed9

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in Aaronontheweb/dotnet-skills, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Csharp Nullable Reference Types next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Csharp Nullable Reference Types compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Csharp Nullable Reference Types this skillAaronontheweb/dotnet-skills1.2k1 repos~2.9kAutomated safety check: PassMIT
Generate Testability Wrappersdotnet/skills5.6k1 repos~3.9kAutomated safety check: PassMIT
Generate Testability Wrappersmicrosoft/testfx1k—~2.2kAutomated safety check: PassMIT
Csharp Dotnetericrisco/rsc-harness156—~3.3kAutomated safety check: PassMIT
Aa Batching PaymastersNethereum/Nethereum2.3k—~1.5kAutomated safety check: PassMIT
Tsp Csharpquerylenshq/ef-querylens225—~1.3kAutomated safety check: PassMIT

Similar skills

  • Official

    DO NOT USE when the target already consumes an injected interface or built-in abstraction such as IFileSystem or TimeProvider, even if the request says "generate a wrapper"; no new wrapper is needed.

    5.6k GitHub starsUsed in 1 repo~3.9k tokens
    Backend & APIsAuto-check passed
  • Official

    Generate wrapper interfaces and DI registration for hard-to-test static dependencies in C.

    1k GitHub stars~2.2k tokensUpdated today
    Backend & APIsAuto-check passed
  • Csharp Dotnet

    ericrisco/rsc-harness

    A skill your agent uses when writing, reviewing, testing, or shipping C / .NET code — ASP.NET Core APIs (minimal APIs vs controllers), EF Core data access, async correctness, solution layout in…

    156 GitHub stars~3.3k tokensUpdated today
    Backend & APIsAuto-check passed
  • Aa Batching Paymasters

    Nethereum/Nethereum

    Help users batch multiple calls into a single UserOperation and sponsor gas with paymasters using Nethereum Account Abstraction.

    2.3k GitHub stars~1.5k tokensUpdated 2 days ago
    Backend & APIsAuto-check passed
  • Tsp Csharp

    querylenshq/ef-querylens

    Comprehensive C and .NET development skill for TSP projects.

    225 GitHub stars~1.3k tokensUpdated 1 mo ago
    Backend & APIsAuto-check passed
  • Aa Bundler

    Nethereum/Nethereum

    Help users run an ERC-4337 bundler using Nethereum — set up in-process or standalone bundlers with mempool, validation, reputation, and JSON-RPC server.

    2.3k GitHub stars~1.2k tokensUpdated 2 days ago
    Backend & APIsAuto-check passed

More from Aaronontheweb/dotnet-skills

All 33 skills in this repo
  • .NET API Compatibility Design

    Aaronontheweb/dotnet-skills

    Applies extend-only design rules to NuGet packages and distributed systems, covering source, binary and wire compatibility and how to deprecate members safely.

    1.2k GitHub starsUsed in 2 repos~2.7k tokens
    Auto-check passed
  • .NET Trimming and Native AOT

    Aaronontheweb/dotnet-skills

    Guides making .NET libraries trimming-safe and Native-AOT compatible: the MSBuild properties, trimming attributes, warning codes and a playbook of safe patterns.

    1.2k GitHub stars~2.9k tokensUpdated 19 days ago
    Auto-check passed
  • Akka.Hosting Actor Patterns

    Aaronontheweb/dotnet-skills

    Shows how to build entity actors with Akka.Hosting so the same code runs in local unit tests and in a sharded cluster in production.

    1.2k GitHub starsUsed in 1 repo~5k tokens
    Auto-check passed
  • Akka.NET Best Practices

    Aaronontheweb/dotnet-skills

    Guidance for Akka.NET actor systems covering EventStream versus DistributedPubSub, supervision, Props versus DependencyResolver, work distribution and testable cluster code.

    1.2k GitHub starsUsed in 1 repo~3.3k tokens
    Auto-check passed
  • Akka.NET Management and Discovery

    Aaronontheweb/dotnet-skills

    Sets up Akka.Management and Cluster.Bootstrap so Akka.NET clusters form through service discovery on Kubernetes, Azure or config instead of static seed nodes.

    1.2k GitHub starsUsed in 1 repo~2.5k tokens
    Auto-check passed
  • Akka.NET Testing Patterns

    Aaronontheweb/dotnet-skills

    Shows how to test Akka.NET actors with Akka.Hosting.TestKit: swapping services for fakes, using TestProbes, and checking persistence, plus when the older TestKit still fits.

    1.2k GitHub starsUsed in 1 repo~2.4k tokens
    Auto-check passed

Works with

Categories

Questions about Csharp Nullable Reference Types

What does Csharp Nullable Reference Types do?

Guidelines for introducing and using nullable reference types (NRT) and System.Diagnostics.CodeAnalysis nullable attributes in C / .NET codebases. Csharp Nullable Reference Types is an agent skill from Aaronontheweb/dotnet-skills.NET codebases.

When should I use Csharp Nullable Reference Types?

Csharp Nullable Reference Types fits situations like: tasks that involve API design.

How do I install Csharp Nullable Reference Types in Claude Code?

Run `npx skills add Aaronontheweb/dotnet-skills --skill csharp-nullable-reference-types -a claude-code`. Or copy the skill folder (skills/csharp-nullable-reference-types in Aaronontheweb/dotnet-skills) into .claude/skills/csharp-nullable-reference-types in your project. Claude Code loads it when a task matches its description.

How do I install Csharp Nullable Reference Types in Codex?

Run `npx skills add Aaronontheweb/dotnet-skills --skill csharp-nullable-reference-types -a codex`. Or copy the skill folder (skills/csharp-nullable-reference-types in Aaronontheweb/dotnet-skills) into .agents/skills/csharp-nullable-reference-types in your project. Codex loads it when a task matches its description.

Can I use Csharp Nullable Reference Types in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add Aaronontheweb/dotnet-skills --skill csharp-nullable-reference-types -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/csharp-nullable-reference-types, .gemini/skills/csharp-nullable-reference-types, .github/skills/csharp-nullable-reference-types and .opencode/skills/csharp-nullable-reference-types in your project.

What does Csharp Nullable Reference Types need to run?

SKILL.md names no scripts, command-line tools or credentials: Csharp Nullable Reference Types is instructions for the agent only.

Does Csharp Nullable Reference Types access the network?

SKILL.md names 1 domain. As links in the text: learn.microsoft.com. This is read from the text; nothing was executed.

Is Csharp Nullable Reference Types safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Csharp Nullable Reference Types use?

Csharp Nullable Reference Types is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Csharp Nullable Reference Types use?

About 2.9k tokens (SKILL.md is roughly 12k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Csharp Nullable Reference Types?

Skills that share tags, products or a category with Csharp Nullable Reference Types: Generate Testability Wrappers (dotnet/skills, 5.6k stars), Generate Testability Wrappers (microsoft/testfx, 1k stars), Csharp Dotnet (ericrisco/rsc-harness, 156 stars) and Aa Batching Paymasters (Nethereum/Nethereum, 2.3k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Csharp Nullable Reference Types?

Aaronontheweb (a GitHub user) maintains it in Aaronontheweb/dotnet-skills, which has 1,202 GitHub stars. The repository holds 33 skills in this directory. The repository was last updated on September 17, 2026.

Source: Aaronontheweb/dotnet-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.