I\'m implementing application that supports plugins. Currently the problem arises when I try to load common assembly that is used both by host application and plugi
Most likely it is your own code that load latest version first - check if CommonLib
is loaded into new app domain right before the call to Load
.
If it is the case you'll need to be very careful in linking your main code to CommonLib
to avoid loading latest version too early. You may even need to use late binding/reflection for it.
I think your problem is the following:
Assembly asm = pluginDomain.GetAssemblies().First(a => a.GetName().Name == "Plugin");
Type p = asm.GetTypes().First(t => t.GetInterfaces().Contains(typeof(IPlugin)));
var pluginInstance = (IPlugin)pluginDomain.CreateInstanceAndUnwrap(asm.FullName, p.FullName);
With this you're loading the updated/outdated type references into the main AppDomain (which has the assembly already loaded in a different version).
I recommend you use the following approach:
I can't say if this is the best version possible, but this one works pretty well for me in an environment where each plugin can load any version of any assembly. With this setup you're pretty much resistant to changing versions or updates and each plugin can use the version it wants.
Let me know if it works for you.