jakobbotsch
jakobbotsch

Reputation: 6337

IL emit - operation could destabilize runtime when storing then loading

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?

Upvotes: 0

Views: 495

Answers (1)

fejesjoco
fejesjoco

Reputation: 11903

Have you declared the local? Does the type of arg0 and loc0 match? Also you know that arg0 in an instance method is the this reference, right?

Upvotes: 3

Related Questions