You receive a "TypeLoadException" error message when you use the Type Library Importer to convert a COM type library definition into a common language runtime assembly (321558)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft .NET Framework 1.0

This article was previously published under Q321558

SYMPTOMS

In Microsoft Visual Studio .NET 2002, when you convert COM type library (.tlb) definitions into common language runtime assemblies, the Type Library Importer (Tlbimp.exe) generates a System.TypeLoadException exception. When this problem occurs, you receive the following error message at the Visual Studio .NET command prompt:
TlbImp error: System.TypeLoadException - Could not load type AssemlbyName.InterfaceName from assemblyAssemlbyName, Version=x.x.x.x.

CAUSE

This problem occurs if the .tlb file that you are converting uses an interface that is defined in another .tlb file. Because the .tlb file uses the interface as a source interface in its coclasses, the Type Library Importer cannot recognize the reference.

RESOLUTION

To resolve this problem, obtain the latest service pack for the Microsoft .NET Framework 1.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

318836 How to obtain the latest .NET Framework 1.0 service pack

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. This problem was first corrected in the .NET Framework 1.0 Service Pack 2.

MORE INFORMATION

Steps to reproduce the behavior

  1. In a text editor such as Notepad, paste the following code in a new file, and then save the file as testlib1.idl.
    [uuid(1F6C0750-5A3B-11d2-944F-0080C7DE32C6), version(1.0)]
    library TestLib1
    {
    	importlib("stdole32.tlb");
    
    	[uuid(2160A7C9-554B-4479-8299-A8E44171BE19)]
    	dispinterface DLoveDotNetListener
    		{
    		properties:
    		methods:
    
    		[id(1)]
    		void OnFooDone
    			(
    			[in] BSTR i_Param1,
    			[in] BSTR i_Param2
    			);
    		};
    }
    
  2. In the text editor, paste the following code in a new file, and then save the file as testlib2.idl.
    [uuid(2F6C0750-5A3B-11d2-944F-0080C7DE32C6), version(1.0)]
    library TestLib2
    	{
    	importlib("stdole32.tlb");
    	importlib("TestLib1.tlb");
    
    	[uuid(3160A7CA-554B-4479-8299-A8E44171BE19)]
    	coclass LoveCSharpClass
    		{
    		[default] interface IUnknown;
    		[source] dispinterface DLoveDotNetListener;
    		};
    	}
    
  3. Open a Visual Studio .NET Command Prompt window. To do this, click Start, point to All Programs, point to Visual Studio .NET, point to Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt.
  4. At the command prompt, type the following command to locate the directory where the test file is located, and then press ENTER:

    cd path

    Note path is a placeholder for the path of the directory where the test file is located.
  5. Run the Microsoft Interface Definition Language (MIDL) compiler (Midl.exe) on the Testlib1.idl file and on the Testlib2.idl file. To do this, run the following commands at the command prompt:

    Midl testlib1.idl

    Midl testlib2.idl

    The testlib1.tlb file and the testlib2.tlb file are generated.
  6. Run the Type Library Importer on the generated .tlb files. To do this, run the following commands at the command prompt:

    Tlbimp testlib1.tlb

    Tlbimp testlib2.tlb

You receive the error message that is mentioned in the "Symptoms" section.

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

824684 Description of the standard terminology that is used to describe Microsoft software updates


Modification Type:MinorLast Reviewed:8/24/2005
Keywords:kbvs2002sp1sweep kbtshoot kbconversion kbfix kbVSNetPreSP1fix kbbug KB321558 kbAudDeveloper