Disable nullable analysis for net4x leg of multi-targeted projects - #14738
Open
HarnageaGabriel wants to merge 1 commit into
Open
Disable nullable analysis for net4x leg of multi-targeted projects#14738HarnageaGabriel wants to merge 1 commit into
HarnageaGabriel wants to merge 1 commit into
Conversation
BCL APIs are not nullable-annotated on .NET Framework, forcing null-forgiving (`!`) suppressions that IDE0370 then flags as unnecessary on the other TFMs of multi-targeted projects. Disable nullable reference type analysis for the net4x compile pass of multi-targeted projects so the suppressions are no longer needed, and remove the now-obsolete IDE0370 severity override. Fixes dotnet#12726
ViktorHofer
reviewed
Aug 25, 2026
ViktorHofer
left a comment
Member
There was a problem hiding this comment.
I would move this code block into Directory.Build.targets and condition on TargetFrameworkIdentifier == '.NETFramework'. Otherwise LGTM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Many BCL APIs are nullable-annotated on modern .NET/netstandard but not on .NET Framework. This forces the codebase to use the null-forgiving (
!) operator to silence nullable warnings that only fire on the net472 leg of multi-targeted projects. Those same!suppressions are then flagged as unnecessary (IDE0370) when the same source compiles for the other TFMs, where the APIs are annotated — a false positive that can't be fixed without breaking the net472 leg.As a stopgap,
.editorconfigcurrently disables IDE0370 repo-wide via:This PR implements the fix proposed in the issue: disable nullable reference type analysis for the net4x compile pass of multi-targeted projects (
src/Directory.Build.props), so the missing BCL annotations there no longer produce spurious warnings and the!suppressions become genuinely unnecessary everywhere. With the root cause fixed, the IDE0370 override in.editorconfigis removed so the rule reverts to its normal severity.Existing
!suppressions in the codebase are left as-is; IDE0370 is only asuggestionseverity, so they won't fail the build and can be cleaned up incrementally.src/Directory.Build.props: set<Nullable>disable</Nullable>when the currentTargetFrameworkstarts withnet4and the project multi-targets (TargetFrameworkscontains;)..editorconfig: remove the now-obsoleteIDE0370.severity = noneoverride and its comment.Fixes #12726
Test plan
.\build.cmd -msbuildEngine dotnet /p:CreateTlb=false /p:CreateBootstrap=false— full solution build succeeds with 0 warnings/0 errors across net472, net11.0, and netstandard2.0 legs (CreateTlb/CreateBootstrapskipped only because this local machine lacks the .NET Framework SDK tools and Visual Studio; both are unrelated to this change).