1
我有3個類庫,LibA,LibB & LibC。這些庫分別定義了類別A,B & C.無法從MEF中的其他庫調用庫
class C
{
public IEnumerable<X> FuncInC()
{
return something;
}
}
LibB被添加爲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, 文化=中立,公鑰= null' 或它的一個依賴關係。系統 找不到指定的文件。「
注:
- 參考的LibC存在LibB,它是建立沒有錯誤。
- 並且所有程序集(在這種情況下輸出dll)都存在於同一個文件夾中。
- 如果我評論代碼「return new C()。FuncInC();」在FuncInB()定義中,&返回一個虛擬對象,它的工作原理沒有錯誤。問題是因爲使用了LibC。
我們已經在使用項目參考。 – 2011-06-20 04:01:37