Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2010 64-bit COM Interop Issue

I am trying to add a VC6 COM DLL to our VS2010RC C# solution. The DLL was compiled with the VC6 tools to create an x86 version and was compiled with the VC7 Cross-platform tools to generate a VC7 DLL.

The x86 version of the assembly works fine as long as the consuming C# project's platform is set to x86. It doesn't matter whether the x64 or the x86 version of the DLL is actually registered. It works with both. If the platform is set to 'Any CPU' I receive a BadImageFormatException on the load of the Interop.<name>.dll.

As for the x64 version, I cannot even get the project to build. I receive the tlbimp error:

TlbImp : error TI0000: A single valid machine type compatible with the input type library must be specified.

Has anyone seen this issue?

EDIT:

I've done a lot more digging into this issue and think this may be a Visual Studio bug. I have a clean solution. I bring in my COM assembly with language agnostic 'Any CPU' selected. The process architecture of the resulting Interop DLL is x86 rather than MSIL.

May have to make the Interop by hand for now to get this to work.

If anyone has another suggestion let me know.

like image 211
Adam Driscoll Avatar asked Mar 15 '10 21:03

Adam Driscoll


1 Answers

This issue can be resolved by opening the CSProj file and adding the following node to any of the '(Configuration)|Any CPU' nodes that are missing it:

<PlatformTarget>AnyCPU</PlatformTarget>

If this node is not present TlbImp will default to x86 and cause issues.

like image 189
Adam Driscoll Avatar answered Nov 06 '22 15:11

Adam Driscoll