Error messages when you attempt to build a Class Library project in Visual Basic .NET or in Visual Basic 2005 (316163)



The information in this article applies to:

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

This article was previously published under Q316163

SYMPTOMS

When you attempt to build a Class Library project in Visual Basic .NET 2002, and the project exposes a Collection type through Component Object Model (COM) interop, the build may fail with the following error message:
COM Interop registration failed. Error loading type library/DLL.
In Visual Basic .NET 2003, you receive the following error message:
COM Interop registration failed. Could not find a type library for assembly 'Microsoft.VisualBasic'.
In Visual Basic 2005, you receive the following error messagess:
error MSB3211:The assembly 'Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not registered for COM Interop. Please register it with regasm.exe /tlb.
error MSB3212: Error: Error loading type library/DLL.

CAUSE

This behavior occurs because the Collection type is defined in the Microsoft.VisualBasic.dll assembly. If the type library for Microsoft.VisualBasic.dll is not registered, the class library cannot be registered correctly.

RESOLUTION

To resolve this issue, follow these steps:
  1. Start the Visual Studio .NET Command Prompt or the Visual Studio 2005 Command Prompt.
  2. Change the current folder to one of the following folders:
    • Windows Directory\Microsoft .NET\Framework\V1.0.3705
    • Windows Directory\Microsoft .NET\Framework\V1.1.4322
    • Windows Directory\Microsoft .NET\Framework\V2.0.50727
  3. Type the following command, and then press the ENTER:

    regasm microsoft.visualbasic.dll

    NOTE: This command creates and registers the type library for Microsoft.VisualBasic.dll.

  4. Switch back to Visual Studio .NET or Visual Studio 2005, and then rebuild the project.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Problem

  1. Start Visual Studio .NET or Visual Studio 2005, and then create a new Visual Basic Class Library project.
  2. On the Project menu, click Add New Item.
  3. In the Add New Item dialog box, select COM Class, and then click Open.

    Note In Visual Studio 2005, click Add instead of Open.
  4. Add a function that exposes a collection to the ComClass1 class, as follows:
    Function Test() As Collection
    
    End Function
    					
  5. Build the project.

    You receive the error message described in the "Symptoms" section of this article.

Modification Type:MajorLast Reviewed:1/25/2006
Keywords:kbvs2005swept kbvs2005applies kberrmsg kbprb KB316163