Microsoft KB Archive/321558

= You receive a &quot;TypeLoadException&quot; error message when you use the Type Library Importer to convert a COM type library definition into a common language runtime assembly =

Article ID: 321558

Article Last Modified on 8/24/2005

-

APPLIES TO


 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * 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. from assembly, Version=.



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 &quot;Applies to&quot; section. This problem was first corrected in the .NET Framework 1.0 Service Pack 2.



Steps to reproduce the behavior
  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(&quot;stdole32.tlb&quot;);

[uuid(2160A7C9-554B-4479-8299-A8E44171BE19)] dispinterface DLoveDotNetListener {       properties: methods:

[id(1)] void OnFooDone (           [in] BSTR i_Param1,            [in] BSTR i_Param2            ); }; }   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(&quot;stdole32.tlb&quot;); importlib(&quot;TestLib1.tlb&quot;);

[uuid(3160A7CA-554B-4479-8299-A8E44171BE19)] coclass LoveCSharpClass {       [default] interface IUnknown; [source] dispinterface DLoveDotNetListener; };   }  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. At the command prompt, type the following command to locate the directory where the test file is located, and then press ENTER:

cd

Note  is a placeholder for the path of the directory where the test file is located. 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.</li> 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

</li></ol>

You receive the error message that is mentioned in the &quot;Symptoms&quot; 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

Keywords: kbtshoot kbbug kbfix kbconversion kbvsnetpresp1fix kbvs2002sp1sweep KB321558

-

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

© Microsoft Corporation. All rights reserved.