Skip to content

Conversation

@MichalStrehovsky
Copy link
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
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Copy link
Contributor

Copilot AI left a comment

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
Copy link
Member

jkotas commented Nov 14, 2025

given this is only reachable for CoreLib privates

@jkotas
Copy link
Member

jkotas commented Nov 14, 2025

/ba-g known timeouts

@jkotas jkotas merged commit 2551e93 into dotnet:main Nov 14, 2025
104 of 111 checks passed
@MichalStrehovsky MichalStrehovsky deleted the asyncreflection branch November 14, 2025 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants