CIL 错误。未找到方法:'?'
我正在编写自己的编译器,因为它很有趣 xD。它使用 Mono.Cecil 编译为 CIL,当我反编译它或查看 CIL 时,它看起来没问题,但是,当我运行它时,我收到崩溃(异常),指出“找不到方法:'?'”。
查看生成崩溃的方法(堆栈跟踪显示哪个方法),这是给定方法的 CIL:
.method public hidebysig virtual
instance class [Totem.Library]Totem.Library.TotemValue Execute () cil managed
{
IL_0000: callvirt class [Totem.Library]Totem.Library.TotemUndefined [Totem.Library]Totem.Library.TotemUndefined::get_Value()
IL_0005: ret
}
Totem.Library 是用 C# 编写的外部 dll(不是用我的编译器编译的,因此应该可以工作)。被访问的属性(TotemUndefine.Value,静态属性)无法引发异常(它只是返回在 TotemUndefine 的静态构造函数中创建的单例)。
我想知道这个 CIL 有什么问题吗?或者是否需要更多信息来查找问题(可以上传完整源代码,到目前为止总共只有几百行)。
I'm writing my own compiler for the fun of it xD. It's compiling to CIL using Mono.Cecil, and when I decompile it or look at the CIL it looks ok, however, when I run it I get a crash (exception) stating that "Method was not found: '?'".
Looking at the method the crash is generated in (stacktrace shows which method) this is the CIL for the given method:
.method public hidebysig virtual
instance class [Totem.Library]Totem.Library.TotemValue Execute () cil managed
{
IL_0000: callvirt class [Totem.Library]Totem.Library.TotemUndefined [Totem.Library]Totem.Library.TotemUndefined::get_Value()
IL_0005: ret
}
Totem.Library is a external dll written in C# (not compiled with my compiler, and should thus work). The property being accessed (TotemUndefined.Value, static property) has no means of causing an exception (it just returns a singleton created in the static constructor of TotemUndefined).
And I was wondering, is there anything wrong with this CIL? Or is more information required to find the issue (can upload full source, only a couple hundred lines in total as of now).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在使用
callvirt
调用静态函数。那是行不通的,只需使用call
即可。You're using
callvirt
to call a static function. That won't work, simply usecall
.