CompositionContainer中通过DirectoryCatalog加载错误的目录 [英] CompositionContainer loading wrong directory through DirectoryCatalog

查看:678
本文介绍了CompositionContainer中通过DirectoryCatalog加载错误的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与MEF的组成容器和目录编目一个奇怪的问题,我传递了一个完整路径包含程序集的文件夹:

I'm running into an odd problem with MEF's composition container and directory catalog where I pass in a full path to a folder containing assemblies:

在C:\ Program Files文件\ MyCompany的\ MyApp的\ BIN

In C:\Program Files\MyCompany\MyApp\Bin

AssemblyA:ExportedTypeA,ExportedTypeB

AssemblyA: ExportedTypeA, ExportedTypeB

AssemblyB:BaseExportedTypeA,BaseExportedTypeB

AssemblyB: BaseExportedTypeA, BaseExportedTypeB

从其他位置上执行(C:\用户\我\ dev的\项目\富\酒吧\ BAR2 \斌\调试\ OtherApp.Exe)

Executed from another location (C:\users\Me\dev\project\foo\bar\bar2\bin\debug\OtherApp.Exe)

在我调用应用程序:

string ProviderPhysicalPath = @"C:\Program Files\MyCompany\MyApp\Bin";
using (DirectoryCatalog catalog = new DirectoryCatalog(ProviderPhysicalPath))
using (CompositionContainer container = new CompositionContainer(catalog))
{
     container.ComposeParts(this);
}

container.ComposeParts(本)我得到以下异常:

该组合物生产的单一组合物的错误。根本原因如下。检查CompositionException.Errors属性更详细的信息。

The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information.

1)无法找到路径的一部分。C:\用户\我\ dev的\项目\富\酒吧\ BAR2 \ BIN \ DEBUG \ BIN \

1) Could not find a part of the path 'C:\USERS\Me\dev\project\foo\bar\bar2\BIN\DEBUG\BIN\'.

什么是令人困惑的是两部分:

What's confusing is two parts:

  1. 为什么在寻找一个目录我还没有规定?
  2. 为什么它追加\ BIN \到执行目录做呢?

有什么我做错了什么?

推荐答案

您可能会运行到这个问题:

You might be running into this problem:

在使用DirectoryCatalog或传递路径AssemblyCatalog构造,MEF将尝试加载组件在默认加载上下文。然而,如果组件不是在探测路径或GAC中,这将是不可能的,和​​MEF将加载它们在负载从上下文代替

When using a DirectoryCatalog or passing a path to the AssemblyCatalog constructor, MEF will attempt to load assemblies in the default load context. However, if the assemblies are not in the probing path or the GAC, this will not be possible, and MEF will load them in the load-from context instead.

@C:\ Program Files文件\ MyCompany的\ MyApp的\ BIN可能不是在探测路径。我不能说我所经历过的问题还是很多探索它。见丹尼尔·普莱斯特德的博客的详细信息,向下滚动到部分程序集加载的问题

@"C:\Program Files\MyCompany\MyApp\Bin" might not be in the probing path. I can't say I have experienced the issue or explored it much. See Daniel Plaisted's Blog for details, scroll down to the section 'Assembly Load Issues'

<一个href="http://blogs.msdn.com/b/dsplaisted/archive/2010/07/13/how-to-debug-and-diagnose-mef-failures.aspx"相对=nofollow>如何调试和诊断MEF故障

这篇关于CompositionContainer中通过DirectoryCatalog加载错误的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆