wpf C# 运行时错误:“由于以下错误,检索具有 CLSID 的组件的 COM 类工厂失败:找不到指定的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37563946/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 13:49:45  来源:igfitidea点击:

C# Runtime error: 'Retrieving the COM class factory for component with CLSID failed due to the following error: specified module could not be found

c#wpfxamldllruntime-error

提问by Noble-Surfer

I am developing a C# application in which the main application window has a 'tabbed' display, with each tab providing a different feature of the application.

我正在开发一个 C# 应用程序,其中主应用程序窗口有一个“选项卡式”显示,每个选项卡提供应用程序的不同功能。

I already have working tabs for a built in web browser, and a 'status' page that displays the status of the connection between the application and a remote server.

我已经有内置 Web 浏览器的工作选项卡,以及显示应用程序和远程服务器之间连接状态的“状态”页面。

I am now trying to add another tab that will act as a 'document reader'.

我现在正在尝试添加另一个将充当“文档阅读器”的选项卡。

Before I started trying to add this functionality inside another tab, I wrote a completely separate 'document reader' application, which is fully functioning. My intention is to now 'copy' the C# and XAML from this working standalone document reader into the source for my main application- adding the XAML markup to a 'new tab', and the C# code to the corresponding .xaml.csfile.

在我开始尝试在另一个选项卡中添加此功能之前,我编写了一个完全独立的“文档阅读器”应用程序,该应用程序功能齐全。我现在的目的是将 C# 和 XAML 从这个工作的独立文档阅读器“复制”到我的主应用程序的源代码中——将 XAML 标记添加到“新选项卡”,并将 C# 代码添加到相应的.xaml.cs文件。

In my standalone document reader application, I was using the MoonPDF library to read the PDF documents, and that was working correctly.

在我的独立文档阅读器应用程序中,我使用 MoonPDF 库来阅读 PDF 文档,并且工作正常。

However, after copying the XAML markup, and C# code behind into my existing application, I kept getting DLLNotFoundExceptions, even though I had copied all of the DLLs for the external library to the binfolder of my application.

但是,在将 XAML 标记和 C# 代码复制到我现有的应用程序后,我不断收到DLLNotFoundExceptions,即使我已将外部库的所有 DLL 复制到bin我的应用程序的文件夹中。

I tried working through this for a while, but couldn't seem to get it working, so I have decided to revert my changes.

我尝试解决这个问题一段时间,但似乎无法让它工作,所以我决定恢复我的更改。

However, when I now try to run my original application, having reverted the changes, I get a XamlParseExceptionwhich says:

但是,当我现在尝试运行我的原始应用程序并恢复更改后,我得到一个XamlParseException说:

Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll

Additional information: 'The invocation of the constructor on type 'Agent.MainWindow' that matches the specified binding constraints threw an exception.' Line number '5' and line position '5'.

抛出异常:PresentationFramework.dll 中的“System.Windows.Markup.XamlParseException”

附加信息:“对与指定绑定约束匹配的类型 'Agent.MainWindow' 的构造函数的调用引发了异常。” 行号“5”和行位置“5”。

When I 'View Detail' on the exception, and inspect the InnerException, it says:

当我在异常上“查看详细信息”并检查 时InnerException,它说:

{"Retrieving the COM class factory for component with CLSID {...} failed due to the following error: 8007007e The specified module could not be found. (Exception from HRESULT: 0x8007007e).":null}

{“由于以下错误,检索具有 CLSID {...} 的组件的 COM 类工厂失败:8007007e 找不到指定的模块。(来自 HRESULT 的异常:0x8007007e)。”:null}

I can't see the PresentationFramework.dllfile anywhere in my folder structure- is that what the issue is here?

我在PresentationFramework.dll文件夹结构中的任何地方都看不到该文件 - 这就是问题所在吗?

When I Google'd the error, I came across the following question on SO: Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154

当我谷歌搜索错误时,我在 SO 上遇到了以下问题:由于以下错误,检索具有 CLSID {XXXX} 的组件的 COM 类工厂失败:80040154

The accepted answer on that question suggests that I should check the project properties, that the platform target is set to 'x86'- I have checked, and it is. The other two most 'upvoted' answers suggest that I may be using a 32-bit process or DLL, and so need to build for 'x86'- I am aware that the MoonPDF library that I am using is 32-bit, and so am already compiling/ running my code for 'x86', rather than 'Any CPU'.

关于该问题的公认答案表明我应该检查项目属性,平台目标设置为“x86” - 我已经检查过,确实如此。另外两个最“赞成”的答案表明我可能正在使用 32 位进程或 DLL,因此需要为“x86”构建 - 我知道我使用的 MoonPDF 库是 32 位的,所以我已经在编译/运行我的“x86”代码,而不是“任何 CPU”。

Are there any other reasons why I might be getting this runtime error? What else can I do to try and resolve it?

我可能会收到此运行时错误还有其他任何原因吗?我还能做些什么来尝试解决它?

回答by StepUp

Just add PresentationFramework.dllto your project where you've taken the exception. It can be done by five steps:

只需添加PresentationFramework.dll到您的项目中您已经例外。它可以通过五个步骤来完成:

  1. Right Click of Mouse at the project in Solution Explorer.
  2. Select Add -> Reference. The Add Reference dialog box opens.
  3. Then Assemblies -> Framework.
  4. Choose PresentationFramework
  5. Click OK when you have selected you necessary library. Selected reference will appear under the References node of the project.
  1. Solution Explorer.
  2. 选择Add -> Reference。添加引用对话框打开。
  3. 然后Assemblies -> Framework
  4. 选择 PresentationFramework
  5. 选择必要的库后,单击“确定”。选定的参考将出现在项目的参考节点下。

Update:

更新:

Change in Visual Studio project properties:

Visual Studio 项目属性的更改:

  1. Project properties
  2. In Build tab
  3. Platform target =X86
  1. 项目属性
  2. 在构建选项卡中
  3. 平台目标 =X86