Skip to content

Disable nullable analysis for net4x leg of multi-targeted projects - #14738

Open
HarnageaGabriel wants to merge 1 commit into
dotnet:mainfrom
HarnageaGabriel:fix-issue-12726-net472-nullable
Open

Disable nullable analysis for net4x leg of multi-targeted projects#14738
HarnageaGabriel wants to merge 1 commit into
dotnet:mainfrom
HarnageaGabriel:fix-issue-12726-net472-nullable

Conversation

@HarnageaGabriel

Copy link
Copy Markdown

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, .editorconfig currently disables IDE0370 repo-wide via:

dotnet_diagnostic.IDE0370.severity = none

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 .editorconfig is removed so the rule reverts to its normal severity.

Existing ! suppressions in the codebase are left as-is; IDE0370 is only a suggestion severity, so they won't fail the build and can be cleaned up incrementally.

  • src/Directory.Build.props: set <Nullable>disable</Nullable> when the current TargetFramework starts with net4 and the project multi-targets (TargetFrameworks contains ;).
  • .editorconfig: remove the now-obsolete IDE0370.severity = none override 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/CreateBootstrap skipped only because this local machine lacks the .NET Framework SDK tools and Visual Studio; both are unrelated to this change).

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
@HarnageaGabriel
HarnageaGabriel deployed to copilot-pat-pool August 18, 2026 20:09 — with GitHub Actions Active
@HarnageaGabriel
HarnageaGabriel deployed to copilot-pat-pool August 18, 2026 20:09 — with GitHub Actions Active

@ViktorHofer ViktorHofer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this code block into Directory.Build.targets and condition on TargetFrameworkIdentifier == '.NETFramework'. Otherwise LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Do not validate nullable annotations when targeting .NET Framework

2 participants