N
Nathan Baulch
For some reason I keep getting an InvalidProgramException when trying to emit a short (Int16) value in a DynamicMethod.
The following code should replicate my problem.
private delegate object TestHandler();
private static void Main()
{
DynamicMethod method = new DynamicMethod("temp", typeof(object), null, typeof(Program));
ILGenerator il = method.GetILGenerator();
il.Emit(OpCodes.Ldc_I4, (short)1000);
il.Emit(OpCodes.Box, typeof(short));
il.Emit(OpCodes.Ret);
TestHandler handler = (TestHandler)method.CreateDelegate(typeof(TestHandler));
Console.WriteLine(handler());
}
The following code should replicate my problem.
private delegate object TestHandler();
private static void Main()
{
DynamicMethod method = new DynamicMethod("temp", typeof(object), null, typeof(Program));
ILGenerator il = method.GetILGenerator();
il.Emit(OpCodes.Ldc_I4, (short)1000);
il.Emit(OpCodes.Box, typeof(short));
il.Emit(OpCodes.Ret);
TestHandler handler = (TestHandler)method.CreateDelegate(typeof(TestHandler));
Console.WriteLine(handler());
}