All rules
CA2264Usage Enabled by default: As warning

Do not pass a non-nullable value to ArgumentNullException.ThrowIfNull

Do not pass a non-nullable value to ArgumentNullException.ThrowIfNull

Microsoft docs

Description

ArgumentNullException.ThrowIfNull throws when the passed argument is null. Certain constructs like non-nullable structs (except for System.Nullable1), type parameters known to be non-nullable structs, 'nameof()' expressions, and 'new' expressions are known to never be null, so ArgumentNullException.ThrowIfNull will never throw. Thus, calling ArgumentNullException.ThrowIfNull` is unnecessary.

In the case of a struct, since ArgumentNullException.ThrowIfNull accepts an object?, the struct is boxed, which causes an additional performance penalty.

Cause

A value that's known to never be null is passed to ArgumentNullException.ThrowIfNull().

How to fix violations

Remove the ArgumentNullException.ThrowIfNull call.

Example

static void Print(int value)
{
    ArgumentNullException.ThrowIfNull(value);
    Console.WriteLine(value);
}

static void Print(int value)
{
    Console.WriteLine(value.Value);
}

When to suppress

It's always safe to suppress this warning.

Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0