Add warning for annotated extension property#120005
Merged
sbomer merged 4 commits intodotnet:mainfrom Sep 25, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a warning for extension properties annotated with DynamicallyAccessedMembersAttribute. The change introduces a new diagnostic (IL2127) that warns users when attempting to use this attribute on extension properties, which are not supported by the trimming tools.
Key changes:
- Adds a new IL2127 warning for extension properties with
DynamicallyAccessedMembersAttribute - Updates test infrastructure to support rooting entire assemblies via a new attribute
- Fixes test issues that were previously hidden by infrastructure bugs
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/tools/illink/src/ILLink.Shared/DiagnosticId.cs | Adds new diagnostic ID IL2127 for extension property warning |
| src/tools/illink/src/ILLink.Shared/SharedStrings.resx | Adds warning message text for the new diagnostic |
| src/tools/illink/src/ILLink.Shared/DataFlow/CompilerGeneratedNames.cs | Adds helper methods to identify extension types |
| src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs | Implements the warning logic for ILLink |
| src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs | Implements the warning logic for Roslyn analyzer |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs | Implements the warning logic for ILC |
| src/tools/illink/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupRootEntireAssemblyAttribute.cs | New test attribute for rooting entire assemblies |
| src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/TestCaseMetadataProvider.cs | Implements support for the new test attribute in ILLink |
| src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/*.cs | Implements support for the new test attribute in ILC |
| src/tools/illink/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs | Updates test verification logic for extension properties |
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs | Updates test with new expected warnings |
| src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/AttributePropertyDataflow.cs | Adds expected warnings for NativeAOT test bug |
| src/tools/illink/test/Mono.Linker.Tests.Cases/RequiresCapability/RequiresInRootAllAssembly.cs | Updates to use new test attribute |
| src/tools/illink/test/Mono.Linker.Tests.Cases/Metadata/RootAllAssemblyNamesAreKept.cs | Updates to use new test attribute |
...llink/test/Mono.Linker.Tests.Cases.Expectations/Metadata/SetupRootEntireAssemblyAttribute.cs
Outdated
Show resolved
Hide resolved
sbomer
commented
Sep 23, 2025
…adata/SetupRootEntireAssemblyAttribute.cs Co-authored-by: Copilot <[email protected]>
jtschuster
approved these changes
Sep 24, 2025
Member
Author
|
/ba-g "unrelated timeout" |
Member
Author
|
/backport to release/10.0 |
Contributor
|
Started backporting to release/10.0: https://github.com/dotnet/runtime/actions/runs/18021392652 |
Contributor
|
@sbomer backporting to "release/10.0" failed, the patch most likely resulted in conflicts: $ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch
Applying: Add warning for annotated extension property
Using index info to reconstruct a base tree...
M src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs
M src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/ResultChecker.cs
M src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
M src/tools/illink/src/ILLink.Shared/DataFlow/CompilerGeneratedNames.cs
M src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs
Falling back to patching base and 3-way merge...
Auto-merging src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs
Auto-merging src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/ResultChecker.cs
CONFLICT (content): Merge conflict in src/coreclr/tools/aot/ILCompiler.Trimming.Tests/TestCasesRunner/ResultChecker.cs
Auto-merging src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs
Auto-merging src/tools/illink/src/ILLink.Shared/DataFlow/CompilerGeneratedNames.cs
CONFLICT (content): Merge conflict in src/tools/illink/src/ILLink.Shared/DataFlow/CompilerGeneratedNames.cs
Auto-merging src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Add warning for annotated extension property
Error: The process '/usr/bin/git' failed with exit code 128Please backport manually! |
sbomer
added a commit
to sbomer/runtime
that referenced
this pull request
Sep 25, 2025
Fixes dotnet#119113 by adding a new warning that is shown by the Roslyn analyzer when attempting to annotate an extension property with DynamicallyAccessedMembersAttribute. The warning is also produced by ILLink and ILC, but only when the compiler-generated extension metadata type (which contains the property in IL) is referenced, for example via reflection or when the assembly is rooted. So in practice this will be caught just by the analyzer. See comments in the code that explain some nuances of the test approach (we need a way to assert `ExpectedWarning`s on the extension properties, but not the compiler-generated methods in the extension metadata type). Testing this uncovered a test bug which was hiding dotnet#120004.
This was referenced Sep 25, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Fixes #119113 by adding a new warning that is shown by the Roslyn analyzer when attempting to annotate an extension property with DynamicallyAccessedMembersAttribute.
The warning is also produced by ILLink and ILC, but only when the compiler-generated extension metadata type (which contains the property in IL) is referenced, for example via reflection or when the assembly is rooted. So in practice this will be caught just by the analyzer.
I considered reusing IL2041 ("The 'DynamicallyAccessedMembersAttribute' is not allowed on methods. It is allowed on method return value or method parameters") but thought it made sense to introduce a new warning code with a message specific to properties.
See comments in the code that explain some nuances of the test approach (we need a way to assert
ExpectedWarnings on the extension properties, but not the compiler-generated methods in the extension metadata type).Testing this uncovered a test bug which was hiding #120004.