Hello
Recently I start playing around with ILGenerator and DynamicILInfo classes and I came to next problem:
When I invoke a dynamic method wich is created with DynamicILInfo I get next error: "Operation could destabilize the runtime"
Identical method which is created with ILGenerator work without a problem.
Code which use ILGenerator:
public delegate int Function();
static void Main(string[] args)
{
int a = 0;
DynamicMethod dm = new DynamicMethod("Function",typeof(int),new Type[0]);
ILGenerator gen = dm.GetILGenerator();
gen.DeclareLocal(typeof(int));
gen.Emit(OpCodes.Ldc_I4_M1);
gen.Emit(OpCodes.Stloc_0);
gen.Emit(OpCodes.Ldloc_0);
gen.Emit(OpCodes.Ret);
Function fn = (Function)dm.CreateDelegate(typeof(Function));
a = fn.Invoke();
}
Code which uses DynamicILInfo:
public delegate int Function();
static void Main(string[] args)
{
int a = 0;
Dyna
View Complete Post