Microsoft KB Archive/315479

= BUG: PE File Is Unverifiable When You Use PEVerify Tool =

Article ID: 315479

Article Last Modified on 4/11/2003

-

APPLIES TO


 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition

-



This article was previously published under Q315479



SYMPTOMS
When you use the PEVerify tool (Peverify.exe) to determine whether a portable executable (PE) file and associated metadata meet type safety requirements, the resulting PE file is unverifiable in some scenarios (such as those shown in the sample code in the &quot;More Information&quot; section of this article), even though it does not use any unsafe code.



CAUSE
The private member X of the class A is accessible only from member functions and friends of the class A. The issue described in the &quot;Symptoms&quot; section of this article occurs when you attempt to &quot;spoof&quot; the C# compiler to circumvent this limitation by tampering with the definition of the class A, which makes the member X public. Under these circumstances, the C# compiler ignores the resolution scope and references the inappropriate DLL file. The code is compiled successfully. The problem occurs only when the code is verified by the PEVerify tool.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Problem
The following four code samples demonstrate how this behavior occurs when you use the PEverify tool: A.cs // Compiler option needed: csc /target:library A.cs public class A {

private int x;    public A  { this.x = 0; }

} ASpoof.cs // Compiler option needed: csc /target:library ASpoof.cs public class A {

public int x;    public A  { this.x = 1; } B.cs // Compiler option needed: csc /r:A.dll /target:library B.cs using System.Reflection; public class B {

public static A mkA {

Assembly x = Assembly.LoadFrom (&quot;A.dll&quot;); A a = (A)x.CreateInstance (&quot;A&quot;); return a;

}

} C.cs // Compiler option needed: csc /r:ASpoof.dll /r:B.dll C.cs public class Demo {

public static void Main {

A a = B.mkA ; System.Console.WriteLine (a.GetType); System.Console.WriteLine (a.x);

}

} Run PEVerify on C.exe. PEVerify returns the following error message:

[IL]: Error: [h:\test\948\c.exe : Demo::Main] [offset 0x00000005]

[opcode stloc.0] [found objref 'A'] [expected objref 'A'] Unexpected type on the stack.

1 Errors Verifying C.exe

However, C.exe runs correctly and returns the expected results.

C.exe output:

A

0

Keywords: kbbug kbnofix KB315479

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.