-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Method binding by name with Type.DefaultBinder.BindToMethod fails with specific condition #66237
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsDescription
Reproduction Steps
public static class Sample
{
public static void SampleMethod(string param1, int param2 = 0, bool param3 = false) { }
}
var methods = typeof(Sample).GetMethods();
var methodArgs = new object?[] { "value", true };
var method = Type.DefaultBinder.BindToMethod(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static, methods, ref methodArgs, null, null, new[] { "param1", "param3" }, out var _);
Expected behaviorFor example, C# compiler can compile the following code. Sample.SampleMethod(param1: "value", param3: true); So I expect that the binding succeeds and no exceptions are thrown. Actual behavior
Regression?I reproduced this issue on the following platforms:
Known WorkaroundsNo response Configuration
I don't think this issue is specific to the configuration. Other informationNo response
|
This does appear to be a bug; the binding mechanism is supposed to account for parameter names and default values. Even if not supported, |
Description
Type.DefaultBinder.BindToMethod
throwsIndexOutOfRangeException
with the following conditions.Reproduction Steps
param1
andparam3
.IndexOutOfRangeException
is thrown at the last line of the above code.Expected behavior
For example, C# compiler can compile the following code.
So I expect that the binding succeeds and no exceptions are thrown.
Actual behavior
IndexOutOfRangeException
is thrown and the binding fails.Regression?
I reproduced this issue on the following platforms:
Known Workarounds
No response
Configuration
I don't think this issue is specific to the configuration.
Other information
No response
The text was updated successfully, but these errors were encountered: