Add global:: qualifier to System namespaces in OptionsValidatorGenerator#125882
Merged
svick merged 2 commits intodotnet:mainfrom Mar 24, 2026
Merged
Conversation
…datorGenerator The source generator emitted [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage] without the global:: prefix. When the consuming project contains a namespace like XXX.System, the compiler resolves System.Diagnostics against that namespace instead of the global one, causing CS0234. All other attributes in the emitter already use global:: consistently; this was the only one missed. Fix dotnet#118476
This was referenced Mar 21, 2026
Member
|
@copilot please invoke the code-review skill and post your analysis/results as a comment on this PR |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Microsoft.Extensions.Options source generator output to consistently qualify UnconditionalSuppressMessage with global::, preventing namespace shadowing issues (e.g., consumer-defined XXX.System) that can break compilation.
Changes:
- Emit
[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(...)]inOptionsValidatorGeneratoroutput. - Update generator baseline
.g.csfiles to reflect the new emitted attribute text.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/Microsoft.Extensions.Options/gen/Emitter.cs | Adds global:: qualifier when emitting UnconditionalSuppressMessage to avoid ambiguous System namespace resolution in consuming projects. |
| src/libraries/Microsoft.Extensions.Options/tests/SourceGenerationTests/Baselines/NetCoreApp/Validators.g.cs | Updates baseline output to match the new globally-qualified attribute emission. |
| src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/UsingInterfaceAsPropertyTypeForLengthAttributesTests.netcore.g.cs | Baseline update for globally-qualified UnconditionalSuppressMessage. |
| src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/OptionsExtendingSystemClassTest.netcore.g.cs | Baseline update for globally-qualified UnconditionalSuppressMessage. |
| src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/GeneratedAttributesTest.netcore.lang11.g.cs | Baseline update for globally-qualified UnconditionalSuppressMessage. |
| src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/GeneratedAttributesTest.netcore.lang10.g.cs | Baseline update for globally-qualified UnconditionalSuppressMessage. |
| src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/EmitterWithCustomValidator.netcore.g.cs | Baseline update for globally-qualified UnconditionalSuppressMessage. |
| src/libraries/Microsoft.Extensions.Options/tests/SourceGeneration.Unit.Tests/Baselines/DataAnnotationAttributesWithParams.g.cs | Baseline update for globally-qualified UnconditionalSuppressMessage. |
rosebyte
approved these changes
Mar 23, 2026
Member
|
I have added the |
3 tasks
rosebyte
approved these changes
Mar 24, 2026
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.
Note
This contribution was authored with the assistance of AI (Claude Code).
Resolves #118476. Following up on report by @Ternstrom.
Summary
The
OptionsValidatorGeneratoremitted[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage(...)]without theglobal::prefix. When the consuming project contains a namespace likeXXX.System, the compiler resolvesSystem.Diagnosticsagainst that namespace instead of the global one, causing:All other attributes in the emitter already use
global::consistently — this was the only one missed.Changes
Emitter.cs: Addglobal::prefix to theUnconditionalSuppressMessageattribute emissionTest Plan