Skip to content

Share more of RuntimeCustomAttributeData between CoreCLR and native AOT - #136837

Merged
MichalStrehovsky merged 4 commits into
dotnet:mainfrom
MichalStrehovsky:share-runtime-custom-attribute-parser
Nov 3, 2026
Merged

MichalStrehovsky merged 4 commits into
dotnet:mainfrom
MichalStrehovsky:share-runtime-custom-attribute-parser

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

Now that the custom attribute blob has the same shape, we can share more of the parsing and activation.

This is a no-diff change for CoreCLR side, the lines should be identical, just moved to the shared file. The only exception is the RuntimeModule -> ResolutionScope renaming.

MichalStrehovsky and others added 2 commits November 2, 2026 20:26
Move the CoreCLR decoding helpers and CustomAttributeDataParser into shared CoreLib sources. Use ResolutionScope and conditionalize NativeAOT metadata handling while retaining CoreCLR's existing behavior.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 44ca18c9-11a3-4f9d-8842-e92a20a377ba
Move CoreCLR attribute activation and argument readers into shared CoreLib sources. Add NativeAOT's trusted constructor-only byref invocation and GC-reporting adapters while preserving CoreCLR behavior. Align NativeAOT constructor exception propagation with CoreCLR.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 44ca18c9-11a3-4f9d-8842-e92a20a377ba
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The NativeAOT change introduces ambiguous property resolution for null enum-array properties that hide inherited properties of a different type, causing attribute creation to fail and requiring type-aware lookup plus a regression test.

1 open issue
What changed in this PR

This PR consolidates custom-attribute parsing and activation in shared CoreLib code for CoreCLR and NativeAOT, with the intent of preserving CoreCLR behavior.

Changes:

  • Moves parsing and activation logic into the shared implementation, retaining runtime-specific metadata handling.
  • Adds NativeAOT support for direct-by-reference constructor invocation and shared GC reporting.
  • Aligns NativeAOT constructor exception propagation with CoreCLR and expands tests to cover parameterless constructors.
File Description
src/​libraries/​System.Runtime/​tests/​System.Reflection.Tests/​CustomAttributeTests.cs Tests unwrapped exceptions from both constructor forms.
src/​libraries/​System.Private.CoreLib/​src/​System/​Runtime/​GCFrameRegistration.cs Adds NativeAOT GC registration wrappers.
src/​libraries/​System.Private.CoreLib/​src/​System/​Reflection/​RuntimeCustomAttributeData.cs Hosts shared attribute parsing and activation.
src/​coreclr/​System.Private.CoreLib/​src/​System/​Reflection/​RuntimeCustomAttributeData.CoreCLR.cs Removes logic moved to shared CoreLib.
src/​coreclr/​nativeaot/​System.Private.Reflection.Execution/​src/​Internal/​Reflection/​Execution/​MethodInvokers/​InstanceMethodInvoker.cs Implements direct-by-reference constructor activation.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​RuntimeCustomAttributeData.NativeAot.cs Removes superseded NativeAOT parsing and activation.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​MethodInfos/​RuntimeConstructorInfo.cs Caches constructor argument types.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​Runtime/​General/​ThunkedApis.cs Adds adapters required by shared activation.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​Reflection/​DynamicInvokeInfo.cs Adds trusted by-reference constructor invocation.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​System/​ActivatorImplementation.cs Makes constructor exception wrapping configurable.
src/​coreclr/​nativeaot/​System.Private.CoreLib/​src/​Internal/​Reflection/​Core/​Execution/​MethodBaseInvoker.cs Defines the direct-by-reference activation entry point.

Review effort: Balanced

Replace the helper-level suppression with a DynamicallyAccessedMembers contract. The custom attribute caller already carries the relevant suppression.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 44ca18c9-11a3-4f9d-8842-e92a20a377ba
Remove forced inlining and the redundant prolog accessor, return RuntimeType directly from NativeAOT type-value decoding, and assert the validated constructor signature invariant in direct byref invocation.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 44ca18c9-11a3-4f9d-8842-e92a20a377ba
@MichalStrehovsky
MichalStrehovsky merged commit 210684d into dotnet:main Nov 3, 2026
136 of 138 checks passed
@MichalStrehovsky
MichalStrehovsky deleted the share-runtime-custom-attribute-parser branch November 3, 2026 11:43
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants