Code inspection: Redundant nullable annotation on base type constraint of type parameter having non-nullable type kind
This inspection reports a nullable annotation on a type constraint when another constraint such as class, struct, unmanaged, or notnull already makes the type parameter non-nullable. In that case, the ? on the constraint is contradictory and has no effect.
#nullable enable
using System;
class C
{
void M<T>() where T : notnull, IDisposable?
{
}
}
#nullable enable
using System;
class C
{
void M<T>() where T : notnull, IDisposable
{
}
}
Depending on the constraint list, another quick-fix can remove the redundant non-nullable type-kind constraint instead.
13 April 2026