Visual Studio 2010 64 位 COM 互操作问题 [英] Visual Studio 2010 64-bit COM Interop Issue

查看:19
本文介绍了Visual Studio 2010 64 位 COM 互操作问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 VC6 COM DLL 添加到我们的 VS2010RC C# 解决方案中.DLL使用VC6工具编译生成x86版本,使用VC7跨平台工具编译生成VC7 DLL.

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.

只要将使用 C# 项目的平台设置为 x86,x86 版本的程序集就可以正常工作.DLL 的 x64 或 x86 版本是否实际注册并不重要.它适用于两者.如果平台设置为任何 CPU",我会在加载 Interop.<name>.dll 时收到 BadImageFormatException.

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.

至于 x64 版本,我什至无法构建项目.我收到 tlbimp 错误:

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

TlbImp:错误 TI0000:与必须指定输入类型库.

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

有人见过这个问题吗?

我对这个问题做了更多的研究,并认为这可能是一个 Visual Studio 错误.我有一个干净的解决方案.我选择了与语言无关的任何 CPU"来引入我的 COM 程序集.生成的 Interop DLL 的进程体系结构是 x86 而不是 MSIL.

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.

现在可能必须手动制作 Interop 才能使其正常工作.

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

如果有人有其他建议,请告诉我.

If anyone has another suggestion let me know.

推荐答案

可以通过打开 CSProj 文件并将以下节点添加到任何缺少它的(配置)|任何 CPU"节点来解决此问题:

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>

如果此节点不存在,TlbImp 将默认为 x86 并导致问题.

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

这篇关于Visual Studio 2010 64 位 COM 互操作问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆