将 x86 平台更改为 Any CPU for .NET 3.5 throws COMException

Change x86 platform to Any CPU for .NET 3.5 throws COMException

我正在尝试将 C# 应用程序的平台目标从 x86 更改为任何 CPU。我的应用程序使用 _click 方法运行一个新线程,该线程打开一个查看器 window 使用以下方法显示 window:

public void Show(string url, int entityId, string sessionId, int projId, string docId)
{
    base.Show();
    try
    {
        this.DocViewer.InitComm(url, entityId, sessionId, projId, docId);
    }
    catch (Exception ex)
    {
        Logger.Error("Error opening viewer", ex);
        throw;
    }
}    

在 x86 平台上 运行 时,应用程序可以正常运行。我将平台更改为 "Any CPU" 并收到 "COMException was unhandled" 错误:"Class not regisered (Exception from HRESULT: 0X80040154 (REGDB_E_CLASSNOTREG))" 突出显示:

base.Show();

我已经研究了这个错误的原因,这似乎是因为 registry redirection. Because I am using .NET 3.5, I have been unable to use many of the solutions that I have found including one from this thread on SO. I am unclear on how the information here 可能会有所帮助,因为很多指向代码的链接都是用 C++ 编写的。

如果有人能为我提供见解,我将不胜感激。

这是完全正常的事故。很明显,您依赖于 COM 服务器,他们非常关心您的程序是在 32 位还是 64 位模式下运行。 COM 服务器是用本机代码编写的,通常是 C++,在 64 位模式下需要不同风格的本机代码。

如果这样的 COM 服务器是 Windows 的一部分并且不太旧,那么您只能指望拥有 64 位版本。但其中绝大多数是第 3 方产品,并且仅提供 32 位版本。如果它是您自己的,那么您必须构建它的 x64 版本,如果它是第 3 方,那么您将不得不使用电话。我们无法帮助您找到号码。如果您需要提示,请查看项目的程序集引用并查看文件的属性,很有可能您会在版权声明中看到供应商名称。