[英]Unable to call a library from other in MEF
我有3个类库,LibA,LibB和LibC。 这些库分别定义了类A,B和C。
class C
{
public IEnumerable<X> FuncInC()
{
return something;
}
}
LibC被添加为LibB中的参考。 B类使用C类。使用MEF,我从LibB中导出了B类。
[Export(typeof(InterfaceForB))]
class B : InterfaceForB
{
public IEnumerable<X> FuncInB()
{
return new C().FuncInC();
}
}
在类A中,我正在使用从B导出的类,如下所示。
public class A : InterfaceForA
{
[Import(typeof(InterfaceForB))]
private InterfaceForB _b;
private CompositionContainer _container;
public A()
{
var _catalog = new DirectoryCatalog(System.IO.Directory.GetCurrentDirectory());
_container = new CompositionContainer(_catalog);
_b = _container.GetExportedValue<InterfaceForB>();
}
public IEnumerable<X> FuncInA()
{
return _b.FuncInB();
}
}
当我运行FuncInA()
,它将引发FileNotFoundException
并显示以下详细信息:
“无法加载文件或程序集'LibC,版本= 1.0.0.0,文化=中性,PublicKeyToken =空”或其依赖项之一。系统找不到指定的文件。”
注意:
在解决方案资源管理器中显示的LibB References中,右键单击LibC的“属性”,将“特定版本”设置为“ False”。
或者更好的方法是,删除二进制引用,并用项目引用替换它(假定LibC与LibB在同一解决方案中)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.