Unloading a DLL

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi All,
Id like to load a "Plugin" into my application that unload the dll so if the dll is updated the updates will take effect.
Here is what I have now:
A Library which defines the plugin Interface - IPlugin. This library also has a method to create an instance of the plugin in a seperate AppDomain:
<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; static IPlugin CreatePlugin(<span style="color:Blue; string strName, <span style="color:Blue; string strAssembly, <span style="color:Blue; string strClassName)
{
ITask objRetTask = <span style="color:Blue; null;
AppDomainSetup objAppDomainSetup = <span style="color:Blue; new AppDomainSetup();
objAppDomainSetup.ApplicationBase = System.Environment.CurrentDirectory;
objAppDomainSetup.ConfigurationFile = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

AppDomain objTaskAppDomain = AppDomain.CreateDomain(String.Format(<span style="color:#A31515; "{0}_{1}", strName, Guid.NewGuid().ToString()), <span style="color:Blue; null, objAppDomainSetup);
Assembly objAssembly = objTaskAppDomain.Load(strAssembly);

objRetPlugin = objAssembly.CreateInstance(strClassName, <span style="color:Blue; true) <span style="color:Blue; as IPlugin;
objRetPlugin.Name = strName;
objRetPlugin.ExecutingDomain = objTaskAppDomain;

<span style="color:Blue; return objRetPlugin
}
[/code]
A Seperal Library of plugin implementations - these would all implement IPlugin.
My main application (a windows service) will call CreatePlugin, pass some valid params and load the plugin. Once Im done with what the plugin I unload it:
<pre>IPlugin objPlugin = PluginFactory.CreatrPlugin(/*The params*/);
// Do some stuff with the plugin (using only IPlugin methods... I never need to cast this to a specific type)
AppDomain.Unload(objPlugin.ExecutingDomain);[/code]
The plugins load and work just fine... the issue Im having is that if I uninstall the Plugin Implementation Library from the GAC and install a new version with some changes... the main app still uses the original implementation. its like the changes are
not loaded... the app just continues to use the original loaded plugin implementation.
Any suggestions?

View the full article
 
Back
Top