IL emit - operation could destabilize runtime when storing then loading
- by Jakob Botsch Nielsen
Hey, so I have the following IL:
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ret);
Which works fine. It basically returns the argument given.
This, however:
il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Ret);
Does not work. It crashes with the exception "Operation could destabilize the runtime.".
Now, I know that the purpose of that is useless but I'm trying to reach my goal by small steps.
Why does that not work?