c# - MEF 插件依赖项未加载,因为未检查插件目录

标签 c# .net mef .net-assembly

我遇到了 MEF 无法为加载的组件获取依赖项的问题。我们的目录结构如下所示:

C:/MSMQ/DistributionService/[主应用]

C:/MSMQ/Providers/[插件组件]

当然,我们使用的是 DirectoryCatalog,该插件已被选中,但其依赖项之一并未被选中。错误信息是:

2012-11-02 10:46:59,379 [1] FATAL - Assemblies required by Provider are not found
System.IO.FileNotFoundException: Could not load file or assembly 'BusinessObjects, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'BusinessObjects, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null'

=== Pre-bind state information ===
LOG: User = <redacted>
LOG: DisplayName = BusinessObjects, Version=1.5.0.0, Culture=neutral, Public
KeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/MSMQ/DistributionService/
LOG: Initial PrivatePath = NULL
Calling assembly : DistributedServicePropertyComponents, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MSMQ\DistributionService\Distr
ibutionService.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\
v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partia
l, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

2012-11-02 10:46:59,401 [1] FATAL - Assemblies required by Provider are not found
System.IO.FileNotFoundException: Could not load file or assembly 'BusinessObjects, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'BusinessObjects, Version=1.5.0.0, Culture=neutral, PublicKeyToken=null'

=== Pre-bind state information ===
LOG: User = B2B\addisona
LOG: DisplayName = BusinessObjects, Version=1.5.0.0, Culture=neutral, Public
KeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/MSMQ/DistributionService/
LOG: Initial PrivatePath = NULL
Calling assembly : DistributedServicePropertyComponents, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\MSMQ\DistributionService\DistributionService.exe.Config
LOG: Using host configuration file:
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\
v4.0.30319\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

我相信这类似于 MSDN 上的一个问题:http://social.msdn.microsoft.com/Forums/en-US/MEFramework/thread/b34ef4f4-e1f1-4f06-bd42-d7b3d5060f6f/ - 但我不明白答案。

是否有任何方法可以提供从中提取问题程序集的路径,或任何其他建议的解决方案?

我们最近才开始遇到这个问题,但我在我们的源代码控制历史记录中看不到任何预期会导致该问题的更改。

最佳答案

您的一个或多个插件依赖于 BusinessObjects 程序集,而您的主机应用程序不引用此程序集。您可以执行以下任一操作来解决此问题:

  1. 从您的主应用程序添加对此程序集的引用,以便插件在加载时可以使用它。
  2. 将此程序集添加到您的 C:\MSMQ\Providers 目录,以便在加载插件并查找该程序集时,它们也可以找到并加载它。

关于c# - MEF 插件依赖项未加载,因为未检查插件目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13231883/

相关文章:

c# - MEF : How can I import a class which has a constructor marked with the ImportingConstructorFlag

c# - 控制台应用程序/服务需要 40 秒才能启动

c# - 寻路算法来查找每个部分是否连接到特定对象

c# - MAF 对比 MEF 对比 Prism

.net - 哪些 .NET 组件使用 Dispatcher?

c# - 在 asp.net 中执行删除之前确认 Linkbutton

.net - 添加对 MEF 插件项目的引用时,为什么会出现警告图标?

c# - 如何以格式 23 :59:59 转换日期时间

c# - 异步操作的非合作取消

c# - 检查我的应用程序是否有权读取进程信息以及读取/写入文件和目录