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



The information in this article applies to:

  • Microsoft Visual Basic .NET (2002)
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET (2003)

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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Open Microsoft Visual Studio .NET or Microsoft Visual Studio 2005.
  2. 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.
  3. Open Module1.vb. Replace the code that initially appears with the following code:
    Imports System.Runtime.InteropServices
    
    Module Module1
    
        <ComImport(), Guid("E436EBB3-524F-11CE-9F53-0020AF0BA770")> _
        Public Class FileGraphManager
    
        End Class
    
        Sub Main()
            Dim fgm As New FileGraphManager()
        End Sub
    
    End Module
    					
  4. On the Build menu, click Build Solution.
  5. 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.
  6. Type the following command:

    peverify test.exe

    This command displays the error described in the "Symptoms" section.

    NOTE: The Peverify tool does not generate an error if you use the code that follows in a Visual C# .NET project:
using System;
using System.Runtime.InteropServices;

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

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

REFERENCES

For more information, refer to the following MSDN article:

Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbnofix kbprb KB313506 kbAudDeveloper