Fix native AOT test failures in System.Reflection.Context tests#125080
Fix native AOT test failures in System.Reflection.Context tests#125080
Conversation
…ion.Context tests Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…tive AOT CI Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Done in 335d280. Reverted the guards that weren't actually failing in PR #124919's CI run: |
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
src/libraries/System.Reflection.Context/tests/ExtendedTypeTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/FinalBranchCoverageTests.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Updates System.Reflection.Context tests to avoid native AOT outerloop failures by conditionally skipping tests that rely on reflection APIs unsupported (or partially unsupported) under native AOT.
Changes:
- Added
[ConditionalFact]guards for method-body reflection APIs (PlatformDetection.IsMethodBodySupported). - Added
[ConditionalFact]guards for metadata token / resolve APIs (PlatformDetection.IsMetadataTokenSupported). - Added
[ConditionalFact]guards for native AOT-unsupported APIs (PlatformDetection.IsNotNativeAot) and assembly-files-dependent behavior (PlatformDetection.HasAssemblyFiles).
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 27 comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Reflection.Context/tests/MoreCoverageTests.cs | Skips a method-body-dependent test when method bodies aren’t supported. |
| src/libraries/System.Reflection.Context/tests/MethodBodyTests.cs | Broadly guards method-body tests to avoid native AOT failures. |
| src/libraries/System.Reflection.Context/tests/FinalCoverageTests2.cs | Guards a filter clause test that relies on method body support. |
| src/libraries/System.Reflection.Context/tests/FinalCoverageTests.cs | Guards a constructor method-body projection test. |
| src/libraries/System.Reflection.Context/tests/FinalBranchCoverageTests.cs | Skips GetInterfaceMap coverage on native AOT. |
| src/libraries/System.Reflection.Context/tests/ExtendedTypeTests.cs | Skips enum values + interface map behavior on native AOT. |
| src/libraries/System.Reflection.Context/tests/ExtendedPropertyInfoTests.cs | Guards MetadataToken usage to only run when supported. |
| src/libraries/System.Reflection.Context/tests/ExtendedFieldInfoTests.cs | Guards MetadataToken usage to only run when supported. |
| src/libraries/System.Reflection.Context/tests/ExtendedAssemblyTests2.cs | Skips tests requiring assembly files / satellite assembly APIs on native AOT. |
| src/libraries/System.Reflection.Context/tests/ExtendedAssemblyTests.cs | Skips referenced assemblies + generic invoke scenarios on native AOT. |
| src/libraries/System.Reflection.Context/tests/CustomTypeTests.cs | Guards MetadataToken usage to only run when supported. |
| src/libraries/System.Reflection.Context/tests/CustomParameterInfoTests.cs | Guards MetadataToken usage to only run when supported. |
| src/libraries/System.Reflection.Context/tests/CustomModuleTests.cs | Guards metadata token/resolve APIs; skips IsResource() on native AOT. |
| src/libraries/System.Reflection.Context/tests/CustomMethodInfoTests.cs | Guards method body + metadata token tests for native AOT compatibility. |
| src/libraries/System.Reflection.Context/tests/CustomEventInfoTests.cs | Guards metadata token; skips GetOtherMethods() on native AOT. |
| src/libraries/System.Reflection.Context/tests/CustomConstructorInfoTests.cs | Guards method body + metadata token tests for native AOT compatibility. |
You can also share your feedback on Copilot code review. Take the survey.
src/libraries/System.Reflection.Context/tests/MethodBodyTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/MethodBodyTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/MethodBodyTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/MethodBodyTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/MethodBodyTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/MethodBodyTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/ExtendedAssemblyTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/ExtendedAssemblyTests2.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Reflection.Context/tests/ExtendedAssemblyTests2.cs
Outdated
Show resolved
Hide resolved
#89157 Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
…tions Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
…eption type unknown Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Implemented in 04733fe and 7f4e2dd:
|
|
/azp run runtime-nativeaot-outerloop |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Tests added in PR #123026 for
System.Reflection.Contextfail in native AOT outerloop runs because they call reflection APIs that throwPlatformNotSupportedExceptionor are otherwise unsupported under native AOT.Changes
Applied guards to only the tests that were actually failing in native AOT CI runs, using the appropriate
PlatformDetectionpredicate,ActiveIssueattribute, or platform-branching assertions for each API category:IsMethodBodySupported—GetMethodBody(),GetILAsByteArray(),ExceptionHandlingClauses,LocalVariables,InitLocals,MaxStackSize,LocalSignatureMetadataToken[ConditionalClass]onMethodBodyTests,ExceptionHandlingClauseTests,LocalVariableInfoTests(constructors callGetMethodBody(), so the entire class is skipped)[ConditionalFact]tests inCustomConstructorInfoTests,CustomMethodInfoTests,FinalCoverageTests,FinalCoverageTests2,MoreCoverageTestsIsMetadataTokenSupported—MetadataToken,ResolveField/Method/Type/MemberCustomConstructorInfoTests,CustomEventInfoTests,CustomMethodInfoTests,CustomModuleTests,CustomParameterInfoTests,CustomTypeTests,ExtendedFieldInfoTests,ExtendedPropertyInfoTestsIsNotNativeAot— APIs that throwPlatformNotSupportedExceptionon native AOT (Module.IsResource(),EventInfo.GetOtherMethods()), plusGetEnumValues()(fails on projected types), and generic methodInvoke()CustomEventInfoTests,CustomModuleTests,ExtendedTypeTests,ExtendedAssemblyTestsPlatform-branching assertions — Instead of skipping, tests assert the expected native AOT behavior:
GetReferencedAssemblies→ assertsPlatformNotSupportedExceptionon native AOT (ExtendedAssemblyTests)GetSatelliteAssembly→ assertsPlatformNotSupportedExceptionon native AOT (ExtendedAssemblyTests2)GetModule→ validatesModule.Namereturns"<Unknown>"when!HasAssemblyFiles(ExtendedAssemblyTests2)ActiveIssue(Type.GetInterfaceMap doesn't work for all cases #89157, native AOT) —GetInterfaceMap()tests that fail due to a known native AOT limitation tracked in issue Type.GetInterfaceMap doesn't work for all cases #89157ExtendedTypeTests.GetInterfaceMap_ReturnsProjectedMappingFinalBranchCoverageTests.GetInterfaceMap_ReturnsMappingOnly tests confirmed as failing in the native AOT CI run were guarded. Tests that were passing on native AOT (including
MethodHandle,FieldHandle,TypeHandle,StructLayoutAttribute,IsSecurityCritical/SafeCritical/Transparent,IsFullyTrusted,GetForwardedTypes,ModuleVersionId,FindTypes, and pointer type tests) remain as plain[Fact].Original prompt
Problem
PR #123026 added new test files to
src/libraries/System.Reflection.Context/tests/that significantly improved code coverage. However, several tests are now failing in native AOT outerloop runs because they use APIs that are not supported on native AOT.Fix Required
Apply the appropriate
[ConditionalFact]guards to tests that use APIs unsupported on native AOT, following the existing patterns in the repo.The key
PlatformDetectionproperties to use are:PlatformDetection.IsMethodBodySupported— for any test callingGetMethodBody(),GetILAsByteArray(),ExceptionHandlingClauses,LocalVariables,InitLocals,LocalSignatureMetadataToken,MaxStackSize, etc.PlatformDetection.IsMetadataTokenSupported— for any test accessingMetadataToken,ResolveField(),ResolveMethod(),ResolveType(),ResolveMember(),ModuleVersionId,FindTypesPlatformDetection.IsNotNativeAot— for tests accessingMethodHandle,FieldHandle,TypeHandle,StructLayoutAttribute,GetForwardedTypes,IsSecurityCritical/IsSecuritySafeCritical/IsSecurityTransparent(on type/constructor/method/field),IsFullyTrusted,GUID, and pointer types (int*)Note that
IsSecurityCritical/IsSecuritySafeCritical/IsSecurityTransparenttests are already guarded for Mono ([ActiveIssue(..., TestRuntimes.Mono)]) but not for native AOT.Files to modify
All the new test files added by PR #123026:
src/libraries/System.Reflection.Context/tests/CustomConstructorInfoTests.csGetMethodBody_ReturnsBody→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMethodBodySupported))]MethodHandle_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]MetadataToken_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]IsSecurityCritical_ReturnsValue,IsSecuritySafeCritical_ReturnsValue,IsSecurityTransparent_ReturnsValue— also add[ActiveIssue(..., TestPlatforms.NativeAot)]or[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]in addition to the existing Mono guardsrc/libraries/System.Reflection.Context/tests/CustomMethodInfoTests.csGetMethodBody_ReturnsBodyWithLocals→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMethodBodySupported))]MethodHandle_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]MetadataToken_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]IsSecurityCritical/SafeCritical/Transparent— also guard for native AOTsrc/libraries/System.Reflection.Context/tests/CustomEventInfoTests.csMetadataToken_ReturnsPositiveValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]src/libraries/System.Reflection.Context/tests/CustomTypeTests.csMetadataToken_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]TypeHandle_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]StructLayoutAttribute_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]IsSecurityCritical_ReturnsValue,IsSecuritySafeCritical_ReturnsValue,IsSecurityTransparent_ReturnsValue→ add[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]src/libraries/System.Reflection.Context/tests/CustomModuleTests.csMetadataToken_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]ModuleVersionId_ReturnsNonEmptyGuid→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsNotNativeAot))]ResolveField_ReturnsProjectedField→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]ResolveMethod_ReturnsProjectedMethod→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]ResolveType_ReturnsProjectedType→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]ResolveMember_ReturnsProjectedMember→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]FindTypes_ReturnsProjectedTypes→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]src/libraries/System.Reflection.Context/tests/CustomParameterInfoTests.csMetadataToken_ReturnsValue→[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsMetadataTokenSupported))]src/libraries/System.Reflection.Context/tests/ExtendedAssemblyTests.csThis pull request was created from Copilot chat.
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.