Code inspection: Redundant nullable annotation on base type constraint of type parameter constrained by another non-nullable base type
This inspection reports a nullable annotation on a type constraint when another constraint already requires the type parameter to be a non-nullable subtype. In that situation, the ? on the constraint is contradictory and has no effect.
Example
#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
{
}
}
Quick-fix
The quick-fix removes the redundant nullable annotation from the type constraint. Another quick-fix can instead annotate the other constraining types as nullable if that better matches the intended generic contract.
13 April 2026