Share Attribute implementation with NativeAOT - #132821
Merged
MichalStrehovsky merged 5 commits intoSep 1, 2026
Merged
Conversation
Use the CoreCLR Attribute implementation in NativeAOT and align the runtime reflection custom attribute layering. Remove the duplicated NativeAOT facade, legacy API aggregation, and generic searcher hierarchy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cdfa51d4-b08c-4fc4-836d-ad41d04d3c15
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Member
Author
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This was referenced Aug 27, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 160e0b66-0384-4c50-b528-c9cd36496cee
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 69dacc0c-3e1b-4730-b772-f4e6132650a4
MichalStrehovsky
marked this pull request as ready for review
August 28, 2026 05:16
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors NativeAOT’s reflection custom-attribute stack to reuse the CoreCLR Attribute implementation and a shared matching/instantiation helper, removing duplicated NativeAOT-only attribute searcher/facade layers. It also re-enables the previously skipped System.Reflection.Context tests on NativeAOT by addressing the underlying attribute-layering mismatch.
Changes:
- Switch NativeAOT to compile and use
System/Attribute.CoreCLR.cs, exposingAttribute.InternalGetAttributeUsagefor the shared attribute matching logic. - Introduce
RuntimeCustomAttributefor NativeAOT and routeGetCustomAttributes*/IsDefined/GetCustomAttributesDataoverrides through it across reflection runtime types. - Delete legacy NativeAOT custom attribute aggregation/searcher infrastructure and re-enable previously skipped tests tied to #73356.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Reflection.Context/tests/CustomReflectionContextTests.cs | Removes NativeAOT ActiveIssue gate so the fixed scenario runs on NativeAOT. |
| src/libraries/System.Reflection.Context/tests/CustomReflectionContext.Examples.cs | Removes NativeAOT ActiveIssue gate for the example-based test. |
| src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs | Makes InternalGetAttributeUsage accessible for reuse and adds helper for attribute array creation; adds NativeAOT-specific usings. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/RuntimeCustomAttribute.NativeAot.cs | New shared helper for matching/instantiating attributes (including inheritance walk where applicable). |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/TypeInfos/RuntimeTypeInfo.cs | Routes custom-attribute APIs through RuntimeCustomAttribute. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/PropertyInfos/RuntimePropertyInfo.cs | Routes custom-attribute APIs through RuntimeCustomAttribute (desktop-compat “inherit ignored” behavior preserved). |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/ParameterInfos/RuntimeParameterInfo.cs | Routes custom-attribute APIs through RuntimeCustomAttribute (desktop-compat “inherit ignored” behavior preserved). |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Modules/RuntimeModule.cs | Routes custom-attribute APIs through RuntimeCustomAttribute (inherit meaningless). |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeMethodInfo.cs | Routes custom-attribute APIs through RuntimeCustomAttribute; updates base-definition traversal to the new override helper. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/MethodInfos/RuntimeConstructorInfo.cs | Routes custom-attribute APIs through RuntimeCustomAttribute. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/LegacyCustomAttributeApis.cs | Deletes legacy NativeAOT per-type “older-style” custom-attribute API implementations. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/General/Helpers.cs | Removes the old InstantiateAsArray helper now superseded by the new attribute pipeline. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/FieldInfos/RuntimeFieldInfo.cs | Routes custom-attribute APIs through RuntimeCustomAttribute. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/EventInfos/RuntimeEventInfo.cs | Routes custom-attribute APIs through RuntimeCustomAttribute (desktop-compat “inherit ignored” behavior preserved). |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/Shared.cs | Reworks implicit-override discovery into a MethodInfo-focused helper with suppression for reflection analysis. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/PropertyPolicies.cs | Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/NestedTypePolicies.cs | Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/MethodPolicies.cs | Adjusts override detection entrypoint to a static helper for the new override discovery flow. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/MemberPolicies.cs | Removes abstract members that were only required for the legacy generic override/member enumeration path. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/FieldPolicies.cs | Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/EventPolicies.cs | Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/BindingFlagSupport/ConstructorPolicies.cs | Removes now-unneeded policy members tied to the old generic override/member enumeration pipeline. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Runtime/Assemblies/RuntimeAssemblyInfo.cs | Routes custom-attribute APIs through RuntimeCustomAttribute (inherit meaningless). |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Attribute.NativeAot.cs | Deletes the NativeAOT-specific Attribute implementation in favor of the shared CoreCLR one. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/System.Private.CoreLib.csproj | Includes CoreCLR Attribute.CoreCLR.cs, adds RuntimeCustomAttribute.NativeAot.cs, and removes legacy custom-attribute sources. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeSearcher.cs | Deletes the legacy generic searcher hierarchy. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Extensions/NonPortable/CustomAttributeInheritanceRules.cs | Deletes legacy matching/inheritance extension layer superseded by the shared implementation. |
| src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs | Removes wrappers that depended on the old generic override/member discovery APIs. |
Member
Author
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
This was referenced Aug 28, 2026
Open
Member
Author
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
jkotas
reviewed
Aug 28, 2026
jkotas
reviewed
Aug 28, 2026
This was referenced Aug 31, 2026
jkotas
approved these changes
Aug 31, 2026
MichalStrehovsky
deleted the
nativeaot-share-attribute-implementation
branch
September 1, 2026 01:04
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.
Deletes 600+ lines of native AOT specific code.
Fixes #73356
Use the CoreCLR Attribute implementation in NativeAOT and align the runtime reflection custom attribute layering. Remove the duplicated NativeAOT facade, legacy API aggregation, and generic searcher hierarchy.