C# 在某些系统上加载带有MEF的程序集失败,并且没有任何错误消息
我对使用MEF的c#应用程序有一个奇怪的问题。我使用以下代码从应用程序的子目录加载插件C# 在某些系统上加载带有MEF的程序集失败,并且没有任何错误消息,c#,.net,dependency-injection,mef,C#,.net,Dependency Injection,Mef,我对使用MEF的c#应用程序有一个奇怪的问题。我使用以下代码从应用程序的子目录加载插件 public class Loader { [ImportMany] private IEnumerable<Lazy<IPlugin, IMeta>> operations = null; public IEnumerable<Lazy<IPlugin, IMeta>> Plugins { get {
public class Loader {
[ImportMany]
private IEnumerable<Lazy<IPlugin, IMeta>> operations = null;
public IEnumerable<Lazy<IPlugin, IMeta>> Plugins {
get {
return this.operations;
}
}
public void Load(string path) {
try {
// An aggregate catalog that combines multiple catalogs
var catalog = new AggregateCatalog();
// Add all the parts found in all assemblies in
// the same directory as the executing program
catalog.Catalogs.Add(new DirectoryCatalog(path));
// Create the CompositionContainer with the parts in the catalog.
CompositionContainer container = new CompositionContainer(catalog);
// Fill the imports of this object
container.ComposeParts(this);
log.Debug("Done loading: " + path);
} catch (Exception error) {
log.Fatal(error);
}
}
}
公共类加载器{
[进口数量]
私有IEnumerable操作=null;
公共IEnumerable插件{
得到{
将此文件返回给操作部门;
}
}
公共无效加载(字符串路径){
试一试{
//组合多个目录的聚合目录
var catalog=new AggregateCatalog();
//添加在中的所有部件中找到的所有零件
//与执行程序相同的目录
catalog.Catalogs.Add(新目录目录(路径));
//使用目录中的零件创建CompositionContainer。
CompositionContainer=新的CompositionContainer(目录);
//填充此对象的导入
容器。组件(本);
调试(“完成加载:+路径”);
}捕获(异常错误){
log.Fatal(错误);
}
}
}
这在我90%的测试系统上运行良好。但在一个系统上,加载程序不加载插件。没有消息或异常。是否有防止MEF动态加载的设置?您的MEF零件在哪里?在系统驱动器上?在文件共享上?应用程序和插件位于本地驱动器上。插件位于相应可执行文件的子目录“plugins”中。