Search code examples
tlbimp

Preventing TlbImp from generating interop assemblies for referenced type libraries


I'm generating interop assemblies using TlbImp. Several of my type libraries reference a single core type library.

When I run TlbImp against First.dll I get Interop.First.dll and Interop.Core.dll. The problem is that when I run it again, against Second.dll, TlbImp tries to generate Interop.Core.dll again, resulting in the error:

TlbImp : error TI0000 : System.ApplicationException - The assembly for referenced
type library, 'Core', will not be imported since it would overwrite existing file
'Core.dll'.

How can I tell TlbImp not to generate interops for referenced assemblies?


Solution

  • I needed to use the /reference parameter to explicitly identify existing interop assemblies.

    Originally I was running these commands:

    > tlbimp Core.dll /out:Interop.Core.dll
    > tlbimp First.dll /out:Interop.First.dll
    > tlbimp Second.dll /out:Interop.Second.dll
    

    TlbImp would try to import the referenced Core.dll and create an interop at Core.dll in the second and third commands, triggering an error.

    To fix this, I just needed to explicitly specify the Core interop:

    > tlbimp Core.dll /out:Interop.Core.dll
    > tlbimp First.dll /reference:Interop.Core.dll /out:Interop.First.dll
    > tlbimp Second.dll /reference:Interop.Core.dll /out:Interop.Second.dll