Skip to content

Fix up reflection with runtime async - #121576

Merged
jkotas merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:asyncreflection
Nov 14, 2025
Merged

jkotas merged 1 commit into
dotnet:mainfrom
MichalStrehovsky:asyncreflection

Conversation

@MichalStrehovsky

Copy link
Copy Markdown
Member

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 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.

Cc @dotnet/ilc-contrib

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.
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
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.

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

@jkotas

jkotas commented Nov 14, 2025

Copy link
Copy Markdown
Member

given this is only reachable for CoreLib privates

@jkotas

jkotas commented Nov 14, 2025

Copy link
Copy Markdown
Member

/ba-g known timeouts

@jkotas
jkotas merged commit 2551e93 into dotnet:main Nov 14, 2025
@MichalStrehovsky
MichalStrehovsky deleted the asyncreflection branch November 14, 2025 06:27
@github-actions github-actions Bot locked and limited conversation to collaborators Dec 14, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants