Closed
Description
Description
Type.DefaultBinder.BindToMethod
throws IndexOutOfRangeException
with the following conditions.
- All the arguments are specified by name.
- Some methods to bind have any unspecified parameters before the specified one.
- All the unspecified parameters have default values.
Reproduction Steps
- Define the following class and method.
public static class Sample
{
public static void SampleMethod(string param1, int param2 = 0, bool param3 = false) { }
}
- Bind to the above method with specifying parameter
param1
andparam3
.
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 _);
IndexOutOfRangeException
is thrown at the last line of the above code.
Expected behavior
For 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
IndexOutOfRangeException
is thrown and the binding fails.
Regression?
I reproduced this issue on the following platforms:
- .NET Core 3.1
- .NET Framework 4.8
Known Workarounds
No response
Configuration
- Runtime: .NET 6.0
- OS: Windows 10 (x64) Home 21H1
I don't think this issue is specific to the configuration.
Other information
No response