471,337 Members | 907 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

C# DLL unloading appdomain

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);
}

Jul 12 '07 #1
2 5424
Tim,
You can't. You can create a new AppDomain, load an assembly into it, and
call methods in the remotely loaded assembly, and tear down the secondary
Appdomain, but the only way you can unload an assembly from your primary
appDomain is the tear down the primary appDomain itself.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Tim" wrote:
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);
}

Jul 12 '07 #2
Tim
On 12 jul, 18:22, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yabbadabbadoo.comwrote:
Tim,
You can't. You can create a new AppDomain, load an assembly into it, and
call methods in the remotely loaded assembly, and tear down the secondary
Appdomain, but the only way you can unload an assembly from your primary
appDomain is the tear down the primary appDomain itself.
Peter
--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder(BETA): http://www.blogmetafinder.com

"Tim" wrote:
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);
}
Peter, Thanks for you quick reply!

Is there a way to invoke methods on the dynamic assembly without
loading it in the main appdomain?

Jul 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by LilleSkutt | last post: by
2 posts views Thread by Arthur Roodenburg | last post: by
5 posts views Thread by vineeth | last post: by
1 post views Thread by Microsoft | last post: by
5 posts views Thread by Bob | last post: by
5 posts views Thread by ECathell | last post: by
reply views Thread by Christian Wulff | last post: by
4 posts views Thread by Jonas Bergman | last post: by
reply views Thread by ibenc | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.