IL 发出 - 存储然后加载时操作可能会破坏运行时的稳定性

发布于 2024-10-08 19:26:10 字数 337 浏览 0 评论 0原文

嘿,所以我有以下 IL:

il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Ret);

效果很好。它基本上返回给定的参数。 然而,这

il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Stloc_0);
il.Emit(OpCodes.Ldloc_0);
il.Emit(OpCodes.Ret);

不起作用。它崩溃并出现异常“操作可能会破坏运行时的稳定性。”。 现在,我知道这样做的目的是没有用的,但我正在努力一步一步地实现我的目标。 为什么那不起作用?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神爱温柔 2024-10-15 19:26:10

你申报本地了吗? arg0 和 loc0 的类型是否匹配?您还知道实例方法中的 arg0 是 this 引用,对吧?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文