EDN Admin
Well-known member
In my PluginManager.cs file I can succefully load my plugin in its own appDomain using this code:
<div style="color:black; background-color:white
<pre> AppDomain d= AppDomain.CreateDomain(loadPlugin.Name);
AssemblyLoader loader = (AssemblyLoader)d.CreateInstanceAndUnwrap(<span style="color:#a31515 "PluginManager", <span style="color:#a31515 "PluginManager.AssemblyLoader");
loader.LoadAndExecute(DllFilePath, <span style="color:blue this <span style="color:blue as IHost);
[/code]
<br/>
The AssemblyLoader looks like this
<div style="color:black; background-color:white
<pre><span style="color:blue public <span style="color:blue class AssemblyLoader : MarshalByRefObject
{
<span style="color:blue internal <span style="color:blue void LoadAndExecute(<span style="color:blue string DllFileToStart, IHost host)
{
<span style="color:blue string assemblyName = <span style="color:#a31515 "";
<span style="color:blue try
{
Assembly w = Assembly.LoadFrom(DllFileToStart);
assemblyName = w.GetName().Name;
Type[] pluginTypes = w.GetTypes();
<span style="color:blue foreach (Type t <span style="color:blue in pluginTypes)
{
<span style="color:blue if (t.GetInterface(<span style="color:#a31515 "IPlugin")!=<span style="color:blue null)
{
IPlugin temp = (IPlugin)Activator.CreateInstance(t);
temp.Host = host;
temp.StartPlugin();
}
}
}
<span style="color:blue catch
{
}
}
}
[/code]
<br/>
Now in the IPlugin interface there is a method called PluginClosed
which is called on the Host (ie pluginManager)
So when the plugin closes it will execute this code in the pluginManager.
public void PluginStopped(IPlugin plugin)
{
AppDomain.Unload(d);
}
In this code i would like to unload the appdomain d for the plugin.
But when i try this i get:
"The application domain in which the thread was running has been unloaded"
So how can i trigger an unload event when the plugin closes in a good way?
<br/>
View the full article
<div style="color:black; background-color:white
<pre> AppDomain d= AppDomain.CreateDomain(loadPlugin.Name);
AssemblyLoader loader = (AssemblyLoader)d.CreateInstanceAndUnwrap(<span style="color:#a31515 "PluginManager", <span style="color:#a31515 "PluginManager.AssemblyLoader");
loader.LoadAndExecute(DllFilePath, <span style="color:blue this <span style="color:blue as IHost);
[/code]
<br/>
The AssemblyLoader looks like this
<div style="color:black; background-color:white
<pre><span style="color:blue public <span style="color:blue class AssemblyLoader : MarshalByRefObject
{
<span style="color:blue internal <span style="color:blue void LoadAndExecute(<span style="color:blue string DllFileToStart, IHost host)
{
<span style="color:blue string assemblyName = <span style="color:#a31515 "";
<span style="color:blue try
{
Assembly w = Assembly.LoadFrom(DllFileToStart);
assemblyName = w.GetName().Name;
Type[] pluginTypes = w.GetTypes();
<span style="color:blue foreach (Type t <span style="color:blue in pluginTypes)
{
<span style="color:blue if (t.GetInterface(<span style="color:#a31515 "IPlugin")!=<span style="color:blue null)
{
IPlugin temp = (IPlugin)Activator.CreateInstance(t);
temp.Host = host;
temp.StartPlugin();
}
}
}
<span style="color:blue catch
{
}
}
}
[/code]
<br/>
Now in the IPlugin interface there is a method called PluginClosed
which is called on the Host (ie pluginManager)
So when the plugin closes it will execute this code in the pluginManager.
public void PluginStopped(IPlugin plugin)
{
AppDomain.Unload(d);
}
In this code i would like to unload the appdomain d for the plugin.
But when i try this i get:
"The application domain in which the thread was running has been unloaded"
So how can i trigger an unload event when the plugin closes in a good way?
<br/>
View the full article