Menu

1 / 3

Even ??= Didn’t Save Me: What Nullable Found in My Old .NET Project

DEV Community: dotnet·Umer Farooq·17 days ago
#n3BLoq8N
#devtodotnet#devto#dev#nullable#null
Long article (2205 words) — no AI summary yet.
Reading 0:00
15s threshold

I recommend ??= all the time. It is one of my favorite C# operators for handling null.

So I was surprised when I turned on nullable reference types in an old project of mine, and the compiler flagged a line that used exactly that operator.

In this post, I will show you what one line in a .csproj found in a real .NET 5 project, why ??= was not enough, and how to turn nullable on in your own codebase without drowning in warnings.

TL;DR: I enabled nullable reference types in an old .NET 5 project with one line in the .csproj . The compiler found 14 null risks without running a single line of code. The most surprising one used ??= , an operator I usually recommend for null safety. Null-safe operators make your code shorter. The compiler is what makes it safe.

The Experiment

The project is a small Heroes API I built on .NET 5: heroes, their achievements, and a CQRS setup with MediatR. Nothing exotic. The kind of code most of us have somewhere.

I have been writing C# since 2016.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.