Referencing a COM assembly in Visual Studio vs converting a COM assembly via tlbimp.exe

assembliesreferencetlbimpvisual studio

When I import a COM assembly (dll) in to a Visual Studio project by adding it as a reference I can use the generated equivalent common language runtime assembly without issue.

However if I try and convert the same COM assembly into a common language runtime assembly using tlbimp I run in to all kinds of problems.

Is there a way to replicate the settings that Visual Studio uses with tlbimp?
Or to put it another way, is there a way to generate the same interop class as visual studio does by using tlbimp?

Best Answer

I found the solution myself. To replicate the settings that Visual Studio uses with tlbimp you simply need to use the /out and /namespace flags.

The out flag is used to prefix "Interop." on the generated file and the namespace flag is used to set the default namespace to the name of the COM assembly.

e.g.

tlbimp /out:Interop.MyCom.dll /namespace:MyCom MyCom.dll