关于peverify错误的问题

发布于 2024-09-08 08:53:51 字数 481 浏览 1 评论 0原文

当我对 .NET exe 运行 peverify 实用程序时,我收到一些错误(类、方法已重命名):

[IL]: Error: [myapp.exe : namespace.class::method1][offset 0x00000027]
Instruction cannot be verified.

[IL]: Error: [myapp.exe : namespace.class::method2][offset 0x00000027]
Instruction cannot be verified.

[IL]: Error: [myapp.exe : namespace.class::method3][offset 0x00000313]
Instruction cannot be verified.

这是我应该担心的事情吗?这些方法都使用 unsafe 关键字,我假设这是导致此错误的原因。但我在网上找不到有关此错误的任何文档,因此任何想法将不胜感激。谢谢!

When I run the peverify utility against my .NET exe, I get a few errors (classes, methods renamed):

[IL]: Error: [myapp.exe : namespace.class::method1][offset 0x00000027]
Instruction cannot be verified.

[IL]: Error: [myapp.exe : namespace.class::method2][offset 0x00000027]
Instruction cannot be verified.

[IL]: Error: [myapp.exe : namespace.class::method3][offset 0x00000313]
Instruction cannot be verified.

Is this something I should be concerned about? These methods all use the unsafe keyword, which I'm assuming is the cause for this error. But I can't find any documentation about this error online, so any thoughts would be much appreciated. Thanks!

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

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

发布评论

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

评论(2

情归归情 2024-09-15 08:53:51

嗯,这并不是因为您使用了不安全关键字。这是因为你写的代码因为使用了unsafe而编译了。是的,peverify 会对这样的代码犹豫不决。这就是不安全的本质。在这里你不能鱼与熊掌兼得。

Well, it is not because you used the unsafe keyword. It is because you wrote code that compiled because you used unsafe. Yes, peverify will balk at such code. it is the very nature of unsafe. You can't have your cake and eat it too here.

忆悲凉 2024-09-15 08:53:51

您在这些方法中使用了 stackalloc 吗?当我在玩这个时,我发现如果 stackalloc 是第一次出现无法验证的代码,那么 peverify 会吐出该错误消息并忽略该方法的其余部分。然而,事实并非如此。如果 stackalloc 稍后出现在方法中,则其他错误将先于 stackalloc 语句生成的错误。也许那是错误?

考虑以下示例。

public static void Main()
{
  unsafe
  {
    int* a = stackalloc int[100];
    int* b = null;
  }
}

我得到以下结果:

[IL]: Error: [myassembly.exe : A.Program::Main][offset 0x00000007] Instruction cannot be verified. 
1 Error(s) Verifying myassembly.exe

但是,如果我注释掉 stackalloc 行,则会得到以下结果:

[IL]: Error: [myassembly.exe : A.Program::Main][offset0x00000004][found Native Int][expected unmanaged pointer] Unexpected type on the stack. 
1 Error(s) Verifying myassembly.exe

Did you use stackalloc in those methods? While I was playing around with this I discovered that if stackalloc is the first occurrence of unverifiable code then peverify spits out that error message and ignores the rest of the method. However, the opposite is not true. If stackalloc appears later in the method then the other errors will precede the error generated by the stackalloc statement. Maybe that is bug?

Consider the following example.

public static void Main()
{
  unsafe
  {
    int* a = stackalloc int[100];
    int* b = null;
  }
}

I get the following result:

[IL]: Error: [myassembly.exe : A.Program::Main][offset 0x00000007] Instruction cannot be verified. 
1 Error(s) Verifying myassembly.exe

However, if I comment out the stackalloc line then I get this result:

[IL]: Error: [myassembly.exe : A.Program::Main][offset0x00000004][found Native Int][expected unmanaged pointer] Unexpected type on the stack. 
1 Error(s) Verifying myassembly.exe
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文