Code inspection: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.
This inspection reports nullable reference type annotations used in auto-generated code without an explicit #nullable directive. In generated files, nullable annotations such as string? are only valid when the source explicitly enables or restores nullable annotations. Without that directive, the annotation context is undefined and the compiler warns.
Example
// <autogenerated />
using System;
string? text = null;
// <autogenerated />
#nullable enable
using System;
string? text = null;
How to fix
There is no dedicated quick-fix for this warning. The usual fix is to add an explicit #nullable directive to the generated file or remove nullable annotations there.
21 April 2026