Visual Studio 2010 64-bit COM Interop Issue
Asked Answered
D

1

17

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.

Diastole answered 15/3, 2010 at 21:9 Comment(0)
D
48

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.

Diastole answered 16/3, 2010 at 19:6 Comment(2)
I wish I could up-vote this a few more times. It's obvious what the error means in retrospect but baffling at first glance.Liquidator
It worked but i needed to add separate <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == '|AnyCPU' "> item in CSProj file in order for VS to start actually using this setting.Thence

© 2022 - 2024 — McMap. All rights reserved.