Repository navigation
Fix up reflection with runtime async - #121576
Merged
Merged
Conversation
The reflection-simple test passes with this fix. The general reflection just falls out naturally. The only thing needed fixing was blocking direct invocation of `AsyncExplicitImpl` methods. We just block this when generating reflection mapping tables. We could also block this within the runtime reflection stack so that we can match the exception type, but given this is only reachable for CoreLib privates, it's really not worth the extra code.
Contributor
|
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes reflection support for runtime async methods by blocking direct invocation of AsyncExplicitImpl methods (non-Task-returning async methods with special calling conventions). The fix adds validation in the AOT compiler's metadata manager and updates tests to account for platform-specific exception behavior.
Key Changes
- Added validation logic to prevent reflection invocation of async methods with non-standard calling conventions
- Updated test expectations to handle different exception types between NativeAOT and other runtimes
- Gated reflection emit test with appropriate conditional attribute
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/tests/async/reflection/reflection-simple.csproj | Added TestLibrary project reference to support platform detection utilities |
| src/tests/async/reflection/reflection-simple.cs | Updated tests to handle NativeAOT-specific exception behavior and gated TypeBuilder test with reflection emit support check |
| src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/MetadataManager.cs | Added validation to exclude non-Task-returning async methods and async variants from reflection invocation mapping tables |
This was referenced Nov 13, 2025
Open
Member
|
jkotas
approved these changes
Nov 14, 2025
Member
|
/ba-g known timeouts |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The reflection-simple test passes with this fix (when I remove
<Optimize>True</Optimize>). The general reflection just falls out naturally. The only thing needed fixing was blocking direct invocation ofAsyncExplicitImplmethods.We just block this when generating reflection mapping tables. We could also block this within the runtime reflection stack so that we can match the exception type, but given this is only reachable for CoreLib privates, it's really not worth the extra code.
Cc @dotnet/ilc-contrib