Skip to content

possible-null-dereference

C#correctnessno fixdefault: offcsharp/roslynator

Reports a member or element access on an expression that the nullable analysis says may be null. Only code under #nullable enable is checked. Off by default: the compiler reports the same thing.

Dereferencing a null reference throws NullReferenceException at run time, so the warning points at a crash that the code allows.

To fix, check for null before the access, or change the type if it cannot be null.

csharp:
lint:
rules:
possible-null-dereference: warn # off (default), warn, error

Enabled by the presets: csharp/roslynator.

Suppress one line with sudsy-disable-next-line possible-null-dereference in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
Roslynator RCS1202 full