Microsoft KB Archive/327128

From BetaArchive Wiki

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

  1. 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
        {
        };
    };
                        
  2. 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
        {
        };
    };
                        
  3. 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.
  4. Compile the .idl files by using the following command lines:
    • midl /win32 One.idl
    • midl /win32 Two.idl
  5. Verify that One.tlb and Two.tlb have been created.
  6. 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
                        
  7. 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

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.


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:


Additional query words: tlbimp TypeLoadException PEVerify

Keywords: kbbug kbpending KB327128