0

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.

arteny
  • 339
  • 1
  • 4
  • 14

1 Answers1

0

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);                
        }
    }
}
Uffe
  • 2,275
  • 1
  • 13
  • 9
  • thank you for answer. It is work example. But your solution is same as mine. As I said I have no problems to load plugins with Composable.LoadAssembly calls. My question was why Composable.AddLocation (dll was loaded only once there, I checked this in Debug Output). But today happened that same code with Composable.AddLocation begins to work. I don't know the reason, but looks my question was a false positive, sorry. – arteny Apr 29 '14 at 17:50