I have need to invoke a method by default value parameters. It has a TargetParameterCountException
by this message :
Parameter count mismatch
var methodName = "MyMethod";
var params = new[] { "Param 1"};
var method = typeof(MyService).GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
method.Invoke(method.IsStatic ? null : this, params);
private void MyMethod(string param1, string param2 = null)
{
}
Why? How can I invoke this method by reflection for default value for parameters?
See Question&Answers more detail:os