C# 8.0 NRT boundary handling for legacy libraries without nullable annotations
0 reputation · 05 Jan 2026, 22:00 UTC
The Challenge
When enabling nullable reference types on an existing codebase, the compiler treats unannotated legacy libraries as 'oblivious'—assuming T? for all reference types. This suppresses warnings but erases static safety guarantees at the call boundary between annotated and unannotated code.
The four-state nullable context model (annotation context and warning context can be set independently) creates complex interactions when generic APIs cross the annotated/oblivious boundary. While #nullable restore can revert project-level settings, there is no mechanism to locally treat a specific external assembly as fully annotated without global enable.
This creates a recovery problem: upgrading incrementally often stalls at the boundary layer where annotated code calls unannotated libraries, forcing either widespread ! null-forgiving operators or acceptance of suppressed warnings that mask real risks.
Specific Questions
- Is there a documented way to locally override the oblivious treatment for a specific NuGet package reference without disabling NRT project-wide?
- Does the compiler provide any configuration or analyzer option to treat unannotated external assemblies as if they were fully annotated with
[Nullable]attributes?