2014-04-28 45 views
0

Composable.AddLocation不適用於我,甚至dll被加載(我可以在輸出窗口中看到它),但GetExport(s)總是返回null。 我使用http://xsockets.net/docs/the-plugin-frameworkXSockets插件框架AddLocation

標準的例子所以此工程:

Composable.LoadAssembly(Path.Combine(Helper.PluginsDirectory, "testplugin.dll")); 

但這並不:

Composable.AddLocation(Helper.PluginsDirectory, SearchOption.AllDirectories, false); 

所有其他代碼是一樣的。

P.S.這裏是解決方案:當我刪除XSockets插件框架dll和dll時,Composable.AddLocation開始工作,它描述了插件目錄中的插件接口。

回答

0

我的猜測是這樣的: 你有已經被插件框架加載的「Helper.PluginsDirectory」文件。 如果您加載其中一個兩次,您將無法獲得導出。

一種解決方法......

class Program 
{ 
    static void Main(string[] args) 
    { 
     Composable.RegisterExport<IAnimal>(); 

     //Helper that fix your issue... 
     Helpers.AddLocation(@"C:\Users\Uffe\Desktop\DynamicAssemblies\Implementation\bin\Debug", SearchOption.AllDirectories); 

     Composable.ReCompose(); 

     var a = Composable.GetExports<IAnimal>(); 
     foreach (var animal in a) 
     { 
      animal.Says(); 
     } 

     Console.ReadLine(); 
    } 

} 

public static class Helpers 
{ 
    public static void AddLocation(string location, System.IO.SearchOption searchOption) 
    { 
     foreach (var assembly in Directory.GetFiles(location, "*.dll", searchOption)) 
     {     
      AssemblyName verifyName = AssemblyName.GetAssemblyName(assembly);         
      if(!Composable.LoadedAssemblies.Any(p => p.FullName == verifyName.FullName)) 
       Composable.LoadAssembly(assembly);     
     } 
    } 
} 
+0

謝謝你的回答。這是工作示例。 但您的解決方案與我的解決方案相同。正如我所說我沒有問題,以加載與Composable.LoadAssembly調用插件。 我的問題是爲什麼Composable.AddLocation(DLL只加載一次,我在調試輸出中檢查了這一點)。 但今天發生的事情是,與Composable.AddLocation相同的代碼開始工作。我不知道原因,但看起來我的問題是誤報,抱歉。 – Arteny