代码之家  ›  专栏  ›  技术社区  ›  Apocalisp

关于验证错误的问题

  •  1
  • Apocalisp  · 技术社区  · 14 年前

    [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关键字,我假设这是导致此错误的原因。但是我在网上找不到关于这个错误的任何文档,所以如果您有任何想法,我将不胜感激。谢谢!

    2 回复  |  直到 14 年前
        1
  •  3
  •   Hans Passant    14 年前

    不是因为你用了 不安全的 关键字。这是因为您编写的代码是因为您使用了不安全的。是的,peverify会对这样的代码犹豫不决。这就是不安全的本质。你不能在这儿吃蛋糕。

        2
  •  1
  •   Brian Gideon    14 年前

    你用过吗 stackalloc 用那些方法?当我玩这个的时候我发现如果 斯塔卡洛克 是第一个出现的不可验证代码,然后peverify抛出错误消息并忽略方法的其余部分。然而,事实并非如此。如果 出现在方法的后面,然后其他错误将出现在 斯塔卡洛克 声明。也许那是虫子?

    考虑下面的例子。

    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
    

    但是,如果我把 然后我得到这个结果:

    [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
    
    推荐文章