.NET Framework plugin system - error on calling Assembly.GetExportedTypes()

33 views Asked by At

We have a third party .NET Framework application that enables users to load their own plugins. Plugins are just standard .NET dlls that the application loads with Assembly.Load().

I'm trying to create a sort of subplugins system, where my plugin loads it's own subplugins.

To test it I created a simple example:

In my plugin dll I declare interface ISubPlugin()

public interface ISubPlugin
{
    void Init();
}

and a bit of code to load subplugins

var asm = Assembly.Load(AssemblyName.GetAssemblyName(@"C:\...\CallbackPluginTest.dll"));
foreach (var t in asm.GetExportedTypes())
{
    foreach (var i in t.GetInterfaces())
    {
        if (i == typeof(ISubPlugin))
        {
            var o = (ISubPlugin)Activator.CreateInstance(t);
            o.InitPlugin();
        }
    }
}

Assembly.Load() works just fine, it loads the subplugin dll, but when asm.GetExportedTypes() is called I get an error saying that it can't find the assembly XXX, where XXX is the assembly that defines ISubPlugin(). So basically .NET can't load assembly that is already loaded, and is in fact the assembly that calls asm.GetEportedTypes(). Weirder still, if I put the XXX assembly dll into the application folder then asm.GetExportedTypes() works, but the condition i == typeof(ISubPlugin) is not met, event though VS debugger shows that it returns true.

Tried searching for some kind of solution or at least an explanation for this behavior on the web but couldn't find anything helpful.

0

There are 0 answers