无法为插件加载特定的dll

时间:2012-03-13 16:06:41

标签: c# plugins mef

我目前正在使用MEF为我的某个应用程序加载插件。我想将bin目录之外的这些插件移动到一个单独的插件目录,以便其他应用程序可以使用插件。我遇到的一个问题是其中一个插件依赖于一个单独的dll中的自定义xml序列化类,当我尝试使用特定的插件时,我得到一个“无法加载文件或程序集”错误尝试加载单独的dll。

我的app.config目前有以下内容:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="plugins"/>
  </assemblyBinding>
</runtime>

我必须按照原始应用程序的顺序添加探测才能使用这个特定的dll。所有插件dll最初都位于bin中称为“plugins”的子目录中。但是现在我想将插件移动到所有应用程序的公共目录中,我会解决这个问题吗?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您必须确保所需的所有依赖项都在您的目录中。

它必须看起来像那样:

var catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
catalog.Catalogs.Add(new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory));//dependencies your plugin dll needs
catalog.Catalogs.Add(new DirectoryCatalog(@"YourPluginFolderPath\Plugins\"));//your plugin dll's

 var cc = new CompositionContainer(catalog);
 var t = cc.GetExport<IMyPluginTestStuffExport>().Value;
相关问题