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# Runtime error: 'Retrieving the COM class factory for component with CLSID failed due to the following error: specified module could not be found

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

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

我现在正尝试添加另一个选项卡作为 'document reader'。

在开始尝试将此功能添加到另一个选项卡之前,我编写了一个完全独立的 'document reader' 应用程序,该应用程序功能齐全。我的意图是现在 'copy' 这个工作的独立文档 reader 中的 C# 和 XAML 到我的主要应用程序的源代码中——将 XAML 标记添加到 'new tab',并将C#代码写入对应的.xaml.cs文件。

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

然而,在将 XAML 标记和隐藏的 C# 代码复制到我现有的应用程序后,即使我已将外部库的所有 DLL 复制到我的应用程序的 bin 文件夹。

我尝试了一段时间,但似乎无法正常工作,所以我决定恢复我的更改。

但是,当我现在尝试 运行 我的原始应用程序时,在恢复更改后,我得到一个 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'.

当我 'View Detail' 出现异常并检查 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}

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

当我 Google 出错时,我在 SO 上遇到了以下问题:Retrieving the COM class factory for component with CLSID {XXXX} failed due to the following error: 80040154

该问题的公认答案建议我检查项目属性,平台目标设置为 'x86'- 我已经检查过,确实如此。其他两个最 'upvoted' 的答案表明我可能正在使用 32 位进程或 DLL,因此需要构建 'x86'- 我知道我正在使用的 MoonPDF 库是 32-位,所以我已经在为 'x86' 而不是 'Any CPU'.

编译/ 运行ning 我的代码

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

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

  1. Solution Explorer 中的项目上单击鼠标右键。
  2. SelectAdd -> Reference。 “添加引用”对话框打开。
  3. 然后Assemblies -> Framework.
  4. 选择PresentationFramework
  5. 选择所需的库后单击“确定”。 Selected 引用将出现在项目的 References 节点下。

更新:

Visual Studio 项目属性的更改:

  1. 项目属性
  2. 在构建选项卡中
  3. 平台目标=X86