MVC 4 MEF:System.TypeLoadException:类型违反的继承安全规则:'DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult'

时间:2015-12-12 04:40:12

标签: c# asp.net-mvc security inheritance mef

导致此错误的原因是什么?

  

System.TypeLoadException:类型违反的继承安全规则:'DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult'。派生类型必须与基类型的安全可访问性匹配,或者不易访问。

我在我的MEF发起人身上发现了这个错误,它从文件夹中读取插件并尝试将其组装到主要应用程序。

这是我的代码:

public class Bootstrapper
{
    private static CompositionContainer CompositionContainer;
    private static bool IsLoaded = false;

    public static void Compose(List<string> pluginFolders)
    {
        if (IsLoaded) return;

        AggregateCatalog catalog = new AggregateCatalog();

        catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),"*"));

        foreach (string plugin in pluginFolders)
        {
            DirectoryCatalog directoryCatalog = new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", plugin), "*");
            catalog.Catalogs.Add(directoryCatalog);
        }

        CompositionContainer = new CompositionContainer(catalog);

        CompositionContainer.ComposeParts();
        IsLoaded = true;
    }
}

我在尝试调试时遇到错误:

catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),"*"));

和此:

DirectoryCatalog directoryCatalog = new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", plugin), "*");
catalog.Catalogs.Add(directoryCatalog);

当我调试代码时,catalog.Parts有这个错误:

  

new System.ComponentModel.Composition.Primitives.ComposablePartCatalogDebuggerProxy(catalog))。Parts'抛出类型'System.Refrection.ReflectionTypeLoadException'的异常

并且catalog.Parts.LoaderException产生错误:

  

System.TypeLoadException:类型违反的继承安全规则:'DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult'。派生类型必须与基类型的安全可访问性匹配,或者不易访问。

我猜测存在安全错误,导致系统无法从另一个文件夹中组装插件。

我的插件文件夹位于:

RootAppFolder
---- Modules
-------- PluginFolder <-- Here

我现在正在构建一个可以在运行时加载插件的MVC 4 CMS。所以我只需要将插件复制到Modules文件夹。我遵循这个guide来实现我的可插拔模块结构。

0 个答案:

没有答案