473,387 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 5541
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: LilleSkutt | last post by:
I want to use assemblies (Window Forms as .dll) so that I can replace the form while the main application is running. To accomplish this, I used Assembly.LoadForm to manually load the assembly when I...
2
by: Arthur Roodenburg | last post by:
Hello, I would like to unload an assembly after I finished my stuff. I tried to load the assembly in to an AppDomain like this: AssemblyName asmName =...
5
by: vineeth | last post by:
Hi I have GUI assembly which is loaded into a seprate Appdomain using AppDomain::Load method, after using it's function i unloaded the assembly by calling the AppDomain.UnLoad() method. But i can...
1
by: Microsoft | last post by:
Hi all, I have some application which dynamically loads a module as a DLL Assembly. Both are written in C#. I also would like to be able to dynamically unload this assembly (i.e. to update the...
5
by: Bob | last post by:
I remember reading somewhere that assemblies can be loaded but not unloaded... I can't seem to find where I read it, but I am looking at a problem where I need to load up an assembly from a file...
5
by: ECathell | last post by:
I have done some searches on this and have found Herfrieds suggestions on opening the DLL in a different appDomain. I have not done this before and am curious on the consequences. Below is the code I...
0
by: Christian Wulff | last post by:
Hi, I have a problem regarding unloading AppDomains in a web service. When I use an AppDomain in a web service and unload it, the referenced assemblies are still locked. When I use the same code...
4
by: Jonas Bergman | last post by:
I have an application that dynamically loads an assembly dureing runtime. I want to send a mesage to the application that a new version of the assembly is available. I then want to unload the...
0
by: ibenc | last post by:
Is there a way to prevent w3wp.exe from unloading a particular appDomain. Some parameters, config files? Here is some info about why I need this. I have a long running background thread in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.