T
Tim
Hello,
I've finally managed to remotely load a DLL. I've expanded the code to
load it in a seperate domain to unload the appdomain, which works to a
certain extend.
The host application always keeps the entry DLL in memory. How can I
also unload this main DLL? As it's left after unloading the appdomain.
The dll is loaded in the hostapplication at "Assembly assembly =
appdom.Load(RawAssembly)".
How can I avoid this behaviour? I would like to invoke a method and
unload the everything dynamically loaded.
Thanks in advance!
The code fragment:
byte[] RawAssembly = getFileArray(FileName);
// AppDomain.CurrentDomain loads also an instance
Assembly assembly = appdom.Load(RawAssembly);
//Assembly assembly = Assembly.LoadFile(FileName);
foreach (AssemblyName ASSN in
assembly.GetReferencedAssemblies())
{
try
{
appdom.CreateInstance(ASSN.Name,
ASSN.GetType().Name);
//
Activator.CreateInstance(ASSN.GetType());
}
catch (Exception e)
{
// MessageBox.Show(e.Message);
}
}
foreach (Type type in assembly.GetTypes())
{
if (!type.IsClass || type.IsNotPublic)
continue;
Type[] interfaces = type.GetInterfaces();
//object obj = Activator.CreateInstance(type);
System.Runtime.Remoting.ObjectHandle t =
appdom.CreateInstance(assembly.GetName().ToString(), type.FullName);
tList.Add(t);
}
I've finally managed to remotely load a DLL. I've expanded the code to
load it in a seperate domain to unload the appdomain, which works to a
certain extend.
The host application always keeps the entry DLL in memory. How can I
also unload this main DLL? As it's left after unloading the appdomain.
The dll is loaded in the hostapplication at "Assembly assembly =
appdom.Load(RawAssembly)".
How can I avoid this behaviour? I would like to invoke a method and
unload the everything dynamically loaded.
Thanks in advance!
The code fragment:
byte[] RawAssembly = getFileArray(FileName);
// AppDomain.CurrentDomain loads also an instance
Assembly assembly = appdom.Load(RawAssembly);
//Assembly assembly = Assembly.LoadFile(FileName);
foreach (AssemblyName ASSN in
assembly.GetReferencedAssemblies())
{
try
{
appdom.CreateInstance(ASSN.Name,
ASSN.GetType().Name);
//
Activator.CreateInstance(ASSN.GetType());
}
catch (Exception e)
{
// MessageBox.Show(e.Message);
}
}
foreach (Type type in assembly.GetTypes())
{
if (!type.IsClass || type.IsNotPublic)
continue;
Type[] interfaces = type.GetInterfaces();
//object obj = Activator.CreateInstance(type);
System.Runtime.Remoting.ObjectHandle t =
appdom.CreateInstance(assembly.GetName().ToString(), type.FullName);
tList.Add(t);
}