IL emit - operation could destabilize runtime when storing then loading

Posted by Jakob Botsch Nielsen on Stack Overflow See other posts from Stack Overflow or by Jakob Botsch Nielsen
Published on 2010-12-24T21:44:57Z Indexed on 2010/12/24 21:54 UTC
Read the original article Hit count: 256

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about c#

Related posts about cil