-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix check for invocation of async infrastructure methods via reflection #121609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Tagging subscribers to this area: @dotnet/area-system-reflection |
0e5d4c3 to
23c468a
Compare
There was a problem hiding this 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 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 |
src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs
Outdated
Show resolved
Hide resolved
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.
01d4d79 to
f944483
Compare
VSadov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
|
/ba-g timeouts |
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.