Skip to content

Conversation

@sbomer
Copy link
Member

@sbomer sbomer commented Sep 25, 2025

Backport of #120005 to 10.0.

Customer Impact

  • Customer reported
  • Found internally

This fixes an issue where DynamicallyAccessedMembers on extension properties (new in .NET 10) is silently ignored. The existing behavior violates user expectations because the attribute has no effect. With the fix, this will be a warning.

Regression

  • Yes
  • No

Testing

Updated tests to validate the new behavior. This behavior was known and tested in the initial change that introduced support for extension members. and we decided after the fact that this should produce a warning.

Risk

Low. This fix is added for completeness in a new .NET 10 feature (trimming support for C# 14 extensions) and does not impact code that doesn't use C# 14 extensions.

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.
@sbomer sbomer requested a review from a team September 25, 2025 21:52
Copilot AI review requested due to automatic review settings September 25, 2025 21:52
@github-actions github-actions bot added the area-Tools-ILLink .NET linker development as well as trimming analyzers label Sep 25, 2025
@sbomer sbomer added Servicing-consider Issue for next servicing release review and removed area-Tools-ILLink .NET linker development as well as trimming analyzers labels Sep 25, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds a warning for DynamicallyAccessedMembers attribute on extension properties, which was previously silently ignored. The change ensures that users are informed when their annotations have no effect on C# 14 extension properties.

Key changes:

  • Introduces IL2127 warning when DynamicallyAccessedMembers is applied to extension properties
  • Updates test infrastructure to support SetupRootEntireAssembly attribute as a replacement for manual linker arguments
  • Adds proper handling of extension properties in dataflow analysis and test result checking

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/tools/illink/src/linker/Linker.Dataflow/FlowAnnotations.cs Adds check for extension properties and emits IL2127 warning
src/tools/illink/src/ILLink.RoslynAnalyzer/DynamicallyAccessedMembersAnalyzer.cs Adds analyzer support for detecting annotated extension properties
src/tools/illink/src/ILLink.Shared/DiagnosticId.cs Defines new IL2127 diagnostic ID
src/tools/illink/src/ILLink.Shared/SharedStrings.resx Adds warning message text for IL2127
src/tools/illink/src/ILLink.Shared/DataFlow/CompilerGeneratedNames.cs Adds utility method to identify extension types
src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/Dataflow/FlowAnnotations.cs Adds same extension property check for NativeAOT
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 Processes new SetupRootEntireAssembly attribute
src/tools/illink/test/Mono.Linker.Tests.Cases/DataFlow/ExtensionMembersDataFlow.cs Updates test to expect IL2127 warnings for extension properties

@dotnet-policy-service dotnet-policy-service bot added the linkable-framework Issues associated with delivering a linker friendly framework label Sep 25, 2025
@rbhanda rbhanda added this to the 10.0.0 milestone Oct 2, 2025
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 2, 2025
* Unify ResultChecker logic

Ports some changes to the ResultChecker logic
from ILLink over to the ILC test infra.
Includes
dotnet@80414e9,
and some other small fixes.

* Clean up
@steveisok steveisok enabled auto-merge (squash) November 4, 2025 03:58
@steveisok
Copy link
Member

/ba-g Known issues dotnet/dnceng#3008 dotnet/dnceng#1883

@steveisok steveisok merged commit 96405dc into dotnet:release/10.0 Nov 10, 2025
109 of 115 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

linkable-framework Issues associated with delivering a linker friendly framework Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants