Microsoft KB Archive/313506

= Visual Basic .NET or Visual Basic 2005 does not support the comImport attribute to manually declare a COM component =

Article ID: 313506

Article Last Modified on 12/6/2006

-

APPLIES TO


 * Microsoft Visual Basic .NET 2002 Standard Edition
 * Microsoft Visual Basic 2005
 * Microsoft Visual Basic .NET 2003 Standard Edition

-



This article was previously published under Q313506



SYMPTOMS
You can use the Peverify.exe tool to verify Microsoft intermediate language (MSIL) and metadata information in a Visual Basic .NET .exe or Visual Basic 2005 .exe file. However, this verification procedure manually declares a Component Object Model (COM) component with a ComImport attribute, and you receive the following the error message:

[MD]: Error: Method marked Abstract/Runtime/InternalCall/Imported must have zero RVA, and vice versa. [token:0x06000003]

1 Errors Verifying test.exe



CAUSE
In Visual Basic .NET or in Visual Basic 2005, you cannot manually declare COM definitions. COM Interop provides access to an existing COM component but does not require that you modify the original component. To reference COM objects and interfaces in Visual Studio .NET or in Visual Studio 2005, you must include a .NET definition for the COM component. In Visual C# .NET, you can manually declare COM definitions if you use the ComImport attribute.



RESOLUTION
To resolve this problem, reference a COM component in Visual Basic .NET or Visual Basic 2005. To do this, add a COM reference to the project. Alternately, you can use the Type Library Importer (Tlbimp.exe) utility to manually create COM Interop assemblies.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Open Microsoft Visual Studio .NET or Microsoft Visual Studio 2005. On the File menu, point to New, and then click Project. Click Visual Basic Projects under Project Types, and then click Console Application under Templates. Type test in the Name text box.

Note In Visual Studio 2005, click Visual Basic under Project Types.  Open Module1.vb. Replace the code that initially appears with the following code: Imports System.Runtime.InteropServices

Module Module1

 _ Public Class FileGraphManager

End Class

Sub Main Dim fgm As New FileGraphManager End Sub

End Module  On the Build menu, click Build Solution. On the Windows Start menu, point to Programs, point to Microsoft Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt. Type the following command:

cd my documents\visual studio projects\test\bin

This command changes the directory to the Bin folder of the test project that you created in the first step of this section.

Note In Visual Studio 2005, click Start, point to Programs, point to Microsoft Visual Studio 2005, and then click Visual Studio 2005 Command Prompt.</li> Type the following command:

peverify test.exe

This command displays the error described in the &quot;Symptoms&quot; section.

NOTE: The Peverify tool does not generate an error if you use the code that follows in a Visual C# .NET project:</li></ol>

using System; using System.Runtime.InteropServices;

namespace test1 {   [ComImport, Guid(&quot;E436EBB3-524F-11CE-9F53-0020AF0BA770&quot;)] class FilgraphManager {    }

class Class1 {       [STAThread] static void Main(string[] args) {       }    } }

<div class="references_section">