Visual Studio 2017:如何运行同时使用 32 位和 64 位 DLL 的应用程序?

Visual Studio 2017:如何运行同时使用 32 位和 64 位 DLL 的应用程序?

问题描述:

我正在尝试运行使用 Nodejs、Edgejs、Angular4 和名为CatalogService.dll"的 C# 后端服务层构建的 Web 应用程序.我正在使用 Visual Studio 2017 来构建 C# 服务.每当我在 Visual Studio 中将平台目标设置为任何 CPU"或x64"并运行应用程序时,我都会收到一条错误消息:

I am trying to run a web application built using Nodejs, Edgejs, Angular4, and a C# back-end services layer that is named "CatalogService.dll". I am using Visual Studio 2017 to build the C# service. Whenever I set the platform target in Visual Studio to "Any CPU" or "x64" and run the app, I get an error saying:

检索 CLSID 为 {EF5A2281-02BA-11D2-8922-AFB2FA76911F} 的组件的 COM 类工厂因以下错误而失败:80040154 类未注册

我在注册表中查找了 CLSIDEF5A2281-02BA-11D2-8922-AFB2FA76911F".CLSID 指的是我计算机上名为 RSEds.dll 的 .dll 文件.CLSID 在 WOW6432Node 下,它告诉我 RSEds.dll 是 32 位 dll,但不是 64 位.

I looked up the CLSID "EF5A2281-02BA-11D2-8922-AFB2FA76911F" in the registry. The CLSID refers to a .dll file named RSEds.dll on my computer. The CLSID was under WOW6432Node, which tells me that RSEds.dll is 32-bit dll, but not 64-bit.

由于 DLL 是 32 位的,我尝试将 Visual Studio 中的目标平台设置为 x86.但是现在当我运行应用程序时,我得到了一个不同的错误:

Since the DLL is 32-bit, I tried setting the target platform in Visual Studio to x86. But now when I run the app, I get a different error:

错误:无法加载文件或程序集CatalogService.dll"或其依赖项之一.试图加载格式不正确的程序.

我的电脑运行的是 Windows 7 x64.我正在处理的 C# 项目依赖于 32 位和 64 位 DLL.我已经面临这个问题超过 4 周了,并尝试了其他几种解决方案:

My computer is running Windows 7 x64. The C# project I am working on depends on both 32-bit and 64-bit DLLs. I have faced this issue for over 4 weeks now and have tried several other solutions:

  • 尝试以管理员身份运行 Regsvr32(32 位和 64 位版本)以注册 RSEds.dll.尽管注册消息说它成功了,但这并没有解决问题.
  • 尝试在 RSEds.dll 上使用 RegAsm,但失败了,因为 RSEds.dll 不是 .NET 程序集.
  • 尝试使用 gacutil/i 将 RSEds.dll 添加到全局程序集缓存 (GAC),但这导致错误:将程序集添加到缓存失败:该模块应包含程序集清单.
  • 尝试更改 IIS 中的应用程序池设置以启用 32 位应用程序,但这不起作用,因为我的 Web 应用程序不使用 IIS.

当 CatalogService.dll 依赖于 32 位和 64 位 dll 时,如何在我的 Web 应用程序中使用它?我确信 RSEds.dll 给我带来了问题,因为它是我的项目使用的唯一 32 位 .dll.有没有办法在 64 位注册表中注册 RSEDs.dll,即使它是 32 位的?

How can I use the CatalogService.dll in my web app when it depends on both 32-bit and 64-bit dlls? I am certain that RSEds.dll is giving me issues because it is the only 32-bit .dll that my project uses. Is there a way I could register the RSEds.dll in the 64-bit registry even though it is 32-bit?

如果没有相应的 64 位 DLL 可用,您可以选择在代理进程内托管 CoClass.这样,即使服务器的位数不匹配,您的客户端也可以创建实例.然而,这种方法的一个缺点是跨进程边界的调用速度较慢.

If there's no corresponding 64-bit DLL available, you have the option of hosting the CoClass inside a surrogate process. This way, your client can create an instance, even if the bitness of the server doesn't match. One drawback of this approach, however, is that calls across process boundaries are slower.

参见这个 回答更多细节.