Microsoft KB Archive/327128

= BUG: TlbImp Silently Produces an Unloadable Assembly Without Warning =

Article ID: 327128

Article Last Modified on 2/23/2007

-

APPLIES TO


 * Microsoft .NET Framework 1.1
 * Microsoft .NET Framework 1.0

-



This article was previously published under Q327128



SYMPTOMS
The Type Library Importer (TlbImp.exe) may import an unloadable assembly without any warning messages. This causes a TypeLoadException exception when you try to run programs (such as PEVerify) on the generated assembly.



CAUSE
This problem occurs when conflicts exist between the name of the imported type library and the names of the type libraries that it references.



RESOLUTION
To resolve this problem, manually create the Component Object Model (COM) Interop assemblies for each type library that is referenced. Use the /references command to reference these assemblies when you import the destination type library by using the TlbImp tool.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
  Use a text editor to create a file that is named One.idl. Copy the following code to the file: [uuid(24b4580a-3c4d-412c-b83d-4e8917af07a2)] library One {   importlib(&quot;stdole2.tlb&quot;);

[       odl, uuid(2be7bcfc-e450-4431-9a10-323f7b6d51bc) ]   interface One : IUnknown {   }; };                      Create a file that is named Two.idl.

This file must reference type library One: [uuid(6f225a10-3c20-4705-a2ac-2e872d943b0e)] library One {   importlib(&quot;One.tlb&quot;);

[       odl, uuid(82f08559-73b6-4093-884b-840f7c69b10f) ]   interface Two: One {   }; };                     To compile these .idl files, click Start, click Programs, click Microsoft Visual Studio .NET, click Visual Studio .NET Tools, and then click Visual Studio .NET Command Prompt. Compile the .idl files by using the following command lines:  midl /win32 One.idl</li> midl /win32 Two.idl</li></ul> </li> Verify that One.tlb and Two.tlb have been created.</li>  Generate the COM Interop assembly by using the TlbImp tool:

tlbimp Two.tlb

The following information appears at the command prompt: <pre class="fixed_text">Microsoft (R) .NET Framework Type Library to Assembly Converter 1.0.3705.0 Copyright (C) Microsoft Corporation 1998-2001. All rights reserved. Type library imported to One.dll </li> Check the assembly by using the PEVerify tool:

peverify One.dll

You receive the following error message:

Microsoft (R) .NET Framework PE Verifier Version 1.0.3705.0

Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.

[IL]: Error: [token 0x02000002] Type load failed.

1 Errors Verifying one.dll

</li></ol>

To resolve this problem, follow these steps to import the type library:


 * 1) Generate the COM Interop assembly for One.tlb:

TlbImp One.tlb

COM Interop assembly One.dll is generated.
 * 1) Generate the COM Interop assembly for Two.tlb. Reference the One.dll assembly file:

TlbImp Two.tlb /out:Two.dll /reference:One.dll


 * 1) Use the PEVerify tool to check the assembly.

<div class="references_section">