【问题标题】:Unable to load specific dll for plugin无法为插件加载特定的 dll
【发布时间】:2012-03-13 16:06:40
【问题描述】:

我目前正在使用 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”的子目录中。但是现在我想将插件移动到所有应用程序的公共目录中,我会去解决这个问题吗?任何帮助将不胜感激。

【问题讨论】:

  • 将自定义 xml 序列化类/插件移动到 GAC 对您来说是一个可行的解决方案吗?
  • 很遗憾我做不到。
  • 奇怪,我也在用MEF;我可以将依赖项放在插件目录中,它就可以工作。你用的是什么目录?我想你无论如何都应该能够使用 ILMerge 加入 dll 的
  • 请发布您如何为您的 compositioncontainer 设置目录

标签: c# plugins mef


【解决方案1】:

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

它必须看起来像这样:

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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-26
    • 2012-01-30
    • 1970-01-01
    相关资源
    最近更新 更多