What causes this error?
System.TypeLoadException: Inheritance security rules violated by type: 'DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult'. Derived types must either match the security accessibility of the base type or be less accessible.
I got this error on my MEF initiator which reads plugins from folder and try to assembly it to the main apps.
Here is my code:
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;
}
}
I got the error when trying to debug this:
catalog.Catalogs.Add(new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"),"*"));
and this:
DirectoryCatalog directoryCatalog = new DirectoryCatalog(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Modules", plugin), "*");
catalog.Catalogs.Add(directoryCatalog);
When i debug the code, catalog.Parts has this error:
new System.ComponentModel.Composition.Primitives.ComposablePartCatalogDebuggerProxy(catalog)).Parts 'Threw an exception of type 'System.Refrection.ReflectionTypeLoadException'
and the catalog.Parts.LoaderException produce error:
System.TypeLoadException: Inheritance security rules violated by type: 'DotNetOpenAuth.Messaging.OutgoingWebResponseActionResult'. Derived types must either match the security accessibility of the base type or be less accessible.
I am guessing that there is security error that prevents the system to assembly the plugin from another folder.
My plugin folder is in:
RootAppFolder
---- Modules
-------- PluginFolder <-- Here
I am now building an MVC 4 CMS that can load plugins on runtime. So i just need to copy the plugin to Modules folder. I am following this guide to achieve my pluggable module structure.