CompositionContainer中通过DirectoryCatalog加载错误的目录加载、错误、目录、CompositionContainer

2023-09-07 09:07:38 作者:断桥残雪

我正在与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:

为什么在寻找一个目录我还没有规定? 为什么它追加\ 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'

如何调试和诊断MEF故障