Uh oh!
There was an error while loading. Please reload this page.
Share Attribute implementation with NativeAOT - #132821
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. |
MichalStrehovsky
commented
Aug 27, 2026
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
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
|
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. |
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. |
MichalStrehovsky
commented
Aug 28, 2026
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
MichalStrehovsky
commented
Aug 28, 2026
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
| #if NATIVEAOT | ||
| using System.Reflection.Runtime.MethodInfos; | ||
| using Internal.Reflection.Augments; |
There was a problem hiding this comment.
using Internal.Reflection.Augments; should not be needed.
We can get rid of using System.Reflection.Runtime.MethodInfos; by changing RuntimeMethodInfo namespace to System.Reflection.
| </ItemGroup> | ||
| <ItemGroup> | ||
| <!-- TODO: (async) once we know which helpers can actually be shared, move those to libraries partition --> | ||
| <CompileInclude="$(CoreClrProjectRoot)System.Private.CoreLib\src\System\Attribute.CoreCLR.cs" /> |
There was a problem hiding this comment.
I assume that this is here just to make the diff easier to review, and it will be moved to libraries Attribute.cs in a follow up
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.