Repository navigation
Fix check for invocation of async infrastructure methods via reflection - #121609
Merged
Merged
Conversation
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-reflection |
jkotas
force-pushed
the
fix-async-reflection
branch
from
November 14, 2025 02:46
0e5d4c3 to
23c468a
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the exception handling when async infrastructure methods are invoked via reflection. Previously, calling AsyncHelpers methods via reflection would throw a TargetInvocationException, but now correctly throws NotSupportedException to match the pattern used for other async methods.
Key changes:
- Added explicit checks in managed code (RuntimeMethodInfo.cs) to detect AsyncHelpers async methods and mark them as non-invokable
- Removed a redundant generic instantiation check in native code that was preventing proper async method detection
- Updated test expectations to verify
NotSupportedExceptionis thrown
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/tests/async/reflection/reflection-simple.cs | Updated test assertion to expect NotSupportedException instead of TargetInvocationException |
| src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs | Added checks to detect AsyncHelpers async methods and throw appropriate exception |
| src/coreclr/vm/reflectioninvocation.cpp | Removed redundant check for shared generic instantiations |
Open
3 tasks
3 tasks
VSadov
reviewed
Nov 14, 2025
This was referenced Nov 14, 2025
MethodInfo.Invoke has multiple implementation strategies. The check for async infrastructure methods needs to be placed in the code that is shared by all implementation strategies. Before this change, this check would not kick under managed debugger or when the test is run with Switch.System.Reflection.ForceEmitInvoke=true appcontext switch. Also, this check should fail with NotSupportedException, without wrapping it in TargetInvocationException() to match existing behaviors.
jkotas
force-pushed
the
fix-async-reflection
branch
from
November 14, 2025 04:10
01d4d79 to
f944483
Compare
jkotas
enabled auto-merge (squash)
November 14, 2025 04:19
jkotas
disabled auto-merge
November 14, 2025 04:20
jkotas
enabled auto-merge (squash)
November 14, 2025 04:20
3 tasks
This was referenced Nov 14, 2025
Member
Author
|
/ba-g 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.
MethodInfo.Invoke has multiple implementation strategies. The check for async infrastructure methods needs to be placed in the code that is shared by all implementation strategies.
Before this change, this check would not kick in under managed debugger or when the test is run with
Switch.System.Reflection.ForceEmitInvoke=trueappcontext switch.Also, this check should fail with NotSupportedException, without wrapping it in TargetInvocationException() to match existing behaviors.