Question about peverify errors
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]
In开发者_如何学Pythonstruction 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!
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.
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
精彩评论