Skip to main content

RCS1256: Invalid argument null check

Properties​

PropertyValue
Default SeverityInfo
Minimum language version-

Summary​

This analyzer reports null checks of arguments that are:

  • annotated as nullable reference type.
  • optional and its default value is null.

Examples​

Example #1​

diagnostic.cs
void M(string? value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));

Foo(value);
}
fix.cs
void M(string? value)
{
Foo(value);
}

Example #2​

diagnostic.cs
void M(string value = null)
{
if (value == null)
throw new ArgumentNullException(nameof(value));

Foo(value);
}
fix.cs
void M(string value = null)
{
Foo(value);
}

Applies to​