-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Improve error reporting for dynamic method invocation via reflection #97022
Comments
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsWhen we invoke a method via reflection, in case something goes wrong with type matching we get this error:
This is a very poor message for debugging. Please give us more information. Something like:
|
The request sounds reasonable; the proposed wording seems a little verbose. Maybe shorten to something like:
It looks like the existing resource string "RFLCT_Targ_ITargMismatch" is used by the managed code in |
@steveharter, thank you so much. |
@steveharter, I would like to take on this issue. |
@Nefcanto or @steveharter |
@RutulPatel8, create a simple class with a single method that takes one parameter which is a string. Now reflect it and call that method, but pass it a list of integers. That's how. |
@Nefcanto Yes I know. how to reproduce this issue. |
@RutulPatel8, I apologize for my misunderstanding. I don't know about that part. |
Oh okay no issue Thanks for the help! |
I believe the solution file you're looking for is this one: https://github.com/dotnet/runtime/blob/main/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.sln |
I was taking a look at this and the error message gets thrown within class MethodInvokerCommon method ValidateInvokeTarget I do find tests within \src\libraries\System.Private.CoreLib\tests\IntrinsicsInSystemPrivatecoreLibAnalyzer.Tests so would assume that somewhere under \tests\ would need a new test class adding for MethodInvokerCommon. I tried to run the existing tests following the instructions from here - But this doesn't appear to work for src\libraries\System.Private.CoreLib\tests\ because there is no solution like there is for something like System.Collections.Immutable which has a solution within the libraries folder. @steveharter - are you able to give some pointers on what I might be missing in terms of how we can run the tests within visual studio for System.Private.CoreLib? |
Which solution did you execute for debugging? |
At this point I have not found any tests to execute. I'm hoping that @steveharter will give us some pointers on how to approach this because there is a solution file that contains libraries\System.Private.CoreLib but it's in coreclr (/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.sln) and does not contain the tests (Maybe it should?) Rest of my questions are in this post - #97022 (comment) |
I think I figured it out - It looks like you need to use the System.Runtime solution which includes the public methods that allow access to System.Private.CoreLib. |
I've been looking at this and have submitted a PR - #98129 @steveharter - I do have a few questions that I'm hoping you can help me with.
|
… and target type does not match passed type (fixes dotnet#97022)
… and target type does not match passed type (#98129) * Added more verbose error message when calling method using reflection and target type does not match passed type (fixes #97022) * Fixed resource string as per PR comment * Fixed the test related to a resource string change * Modified test to have a contains check rather than validating the English string. * Modifications to AOT implementation for validating target type when a method is invoked using reflection, inline with other PR changes
When we invoke a method via reflection, in case something goes wrong with type matching we get this error:
This is a very poor message for debugging. Please give us more information. Something like:
The text was updated successfully, but these errors were encountered: