Reputation: 1121
Is it possible to call a delegate
that takes as a parameter params string[]
from a dynamic method?
Example:
delegate string Del(params string[] arg);
...
Del f = args => "Called successfully.";
...
var mb = typeBuilder.DefineMethod(
"MyMethod",
MethodAttributes.Public | MethodAttributes.Virtual,
typeof(string),
new Type[] {typeof(string), typeof(string)});
...
var generator = mb.GetILGenerator();
...
generator.Emit(OpCodes.Ldarg_0);
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Ldarg_2);
...
generator.Emit(OpCodes.Call, f.GetType().GetMethod("Invoke"));
Because whenever I run the code above, it gives me this:
Unhandled Exception: System.InvalidProgramException: JIT Compiler encountered an internal limitation.
Am I doing something wrong here?
Upvotes: 1
Views: 70
Reputation: 26642
You must pass the array of strings. The "params" keyword is just for syntactic sugar in c#/vb but is ignored in IL.
Upvotes: 0