开发者

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?


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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜