Question

Composable.AddLocation doesn't works for me, even dll is loaded (i can see it in output window), but GetExport(s) return null always. I used standard example from http://xsockets.net/docs/the-plugin-framework

So this works:

Composable.LoadAssembly(Path.Combine(Helper.PluginsDirectory, "testplugin.dll"));

But this doesn't:

Composable.AddLocation(Helper.PluginsDirectory, SearchOption.AllDirectories, false);

All other code is same.

P.S. Here is solution: Composable.AddLocation begins to work when I deleted XSockets Plug-in Framework dll and dll, which describes plugin interface from Plugins directory.

Was it helpful?

Solution

My guess is this: You have files in "Helper.PluginsDirectory" that is already loaded by the plugin framework. If you load one of them twice you will not be able to get the export.

A workaround...

class Program
{
    static void Main(string[] args)
    {
        Composable.RegisterExport<IAnimal>();

        //Helper that fix your issue...  
        Helpers.AddLocation(@"C:\Users\Uffe\Desktop\DynamicAssemblies\Implementation\bin\Debug", SearchOption.AllDirectories);

        Composable.ReCompose();

        var a = Composable.GetExports<IAnimal>();
        foreach (var animal in a)
        {
            animal.Says();
        }

        Console.ReadLine();
    }

}

public static class Helpers
{
    public static void AddLocation(string location, System.IO.SearchOption searchOption)
    {
        foreach (var assembly in Directory.GetFiles(location, "*.dll", searchOption))
        {                
            AssemblyName verifyName = AssemblyName.GetAssemblyName(assembly);                                   
            if(!Composable.LoadedAssemblies.Any(p => p.FullName == verifyName.FullName))  
                Composable.LoadAssembly(assembly);                
        }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top