Code inspection: Redundant nullable attribute
This inspection reports nullable flow-analysis attributes such as [MaybeNull], [NotNull], or [MaybeNullWhen(...)] when the target type and existing contracts already make the attribute unnecessary. In that case, the attribute adds noise without strengthening the API contract.
#nullable enable annotations
using System.Diagnostics.CodeAnalysis;
class C
{
[return: NotNull]
public extern string? GetText();
}
#nullable enable annotations
class C
{
public extern string? GetText();
}
This commonly happens when the type itself already communicates the same nullability information.
13 April 2026