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.
MORE INFORMATION
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("stdole2.tlb"); [ 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("One.tlb"); [ 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
- midl /win32 Two.idl
- Verify that One.tlb and Two.tlb have been created.
Generate the COM Interop assembly by using the TlbImp tool:
tlbimp Two.tlb
The following information appears at the command prompt: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
- Check the assembly by using the PEVerify tool:
peverify One.dll
You receive the following error message:
To resolve this problem, follow these steps to import the type library:
- Generate the COM Interop assembly for One.tlb:
TlbImp One.tlb
COM Interop assembly One.dll is generated.
- Generate the COM Interop assembly for Two.tlb. Reference the One.dll assembly file:
TlbImp Two.tlb /out:Two.dll /reference:One.dll
- Use the PEVerify tool to check the assembly.
REFERENCES
For additional information about generating a COM Interop assembly, click the article number below to view the article in the Microsoft Knowledge Base:
317157 PRB: Errors When You Reference the Access 10.0 Type Library with Visual Studio .NET
For more information about the .NET Framework tools, visit the following MSDN Web site:
.NET Framework Tools
http://msdn.microsoft.com/library/en-us/cptools/html/cpconnetframeworktools.asp
Additional query words: tlbimp TypeLoadException PEVerify
Keywords: kbbug kbpending KB327128