【问题标题】:Loading third party assembly referenced only by plugins with AssemblyCatalog使用 AssemblyCatalog 加载仅由插件引用的第三方程序集
【发布时间】:2013-01-15 15:01:58
【问题描述】:

我在 Windows Azure 应用程序中使用 MEF,其中所有程序集插件都存储在 blob 存储中。在 blob 存储中不仅存储插件,还存储插件引用的所有程序集。

加载插件的代码如下:

foreach (var pluginBytes in _pluginProvider.GetPlugins())
{
    var pluginAssembly = AppDomain.CurrentDomain.Load(pluginBytes);
    var assemblyCatalog = new AssemblyCatalog(pluginAssembly);
    catalog.Catalogs.Add(assemblyCatalog);
}

不幸的是,当在 CompositionContainer 上调用 ComposeParts 方法时,引用第三方程序集的插件将导致 ReflectionTypeLoadException。

由于云解决方案,我无法使用 DirectoryCatalog。 我该如何解决这个棘手的问题?

【问题讨论】:

    标签: c# clr mef .net-assembly


    【解决方案1】:

    如果您在另一个 blob 中有第三方程序集,那么您可以订阅应用程序的域 AssemblyResolve 事件并使用 arg.Name 值从 blob 中找到第三方程序集。然后以与加载插件相同的方式加载它并返回加载程序集的引用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-09
      • 1970-01-01
      • 2014-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多