473,883 Members | 1,570 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Possible Buy/Issue with AppDomain.UnLoa d

I think I've found a possible issue with .Net AppDomain.Unloa d when
using attribute LoaderOptimizat ion.MultiDomain .

Here you will need ProcessExplorer from SysInternals to see what
assemblies are loaded for a given process.

You will need to add the following code into HelloWorld1.cs and compile
through the CS compiler. csc HelloWorld1.cs

// C# Sample Code
// File: HelloWorld1.cs

using System;
using System.Threadin g;

public class HelloWorld
{
public void SayHello(String greeting)
{
Console.WriteLi ne("In the application domain: " +
Thread.GetDomai n().FriendlyNam e);
Console.WriteLi ne(greeting);
}

public static void Main( String[] argv )
{
HelloWorld o = new HelloWorld();
o.SayHello("Hel lo World!");
}
}

You will need to add the following code into ExecAssembly.cs and
compile through the CS compiler. csc ExecAssembly.cs
// C# Sample Code
// File: ExecAssembly.cs
// Creates a remote application domain and executes an assembly
// within that application domain.

using System;
using System.Reflecti on;
using System.Runtime. Remoting;

public class ExecAssembly
{
// By un-commenting the line below causes the problem.
//[LoaderOptimizat ion(LoaderOptim ization.MultiDo main)]
public static void Main( String[] argv )
{
// Set ApplicationBase to the current directory
AppDomainSetup info = new AppDomainSetup( );
info.Applicatio nBase = "file:///" +
System.Environm ent.CurrentDire ctory;

// Create an application domain with null evidence
AppDomain dom = AppDomain.Creat eDomain("Remote Domain", null, info);

// Tell the AppDomain to execute the assembly
dom.ExecuteAsse mbly("HelloWorl d1.exe");

// Clean up by unloading the application domain
AppDomain.Unloa d(dom);
Console.WriteLi ne("HelloWorld 1 UnLoaded");
int i = Console.Read ();
}
}

Now run the ExecAssembly.ex e and while the message HelloWorld1.Unl oaded
is displayed check through ProcessExplorer and you will notice the EXE
HelloWorld1.exe is not listed.

Now un-comment the line
[LoaderOptimizat ion(LoaderOptim ization.MultiDo main)] in module
ExecAssembly.cs and recompile the code. csc ExecAssembly.cs

Now run the ExecAssembly.ex e and while the message HelloWorld1.Unl oaded
is displayed check through ProcessExplorer and you will notice the EXE
HelloWorld1.exe now listed.

The problem is this the framework is not unloading the assembly because
its hold in the shared domain, I thought the shared domain would be
intelligent enough to know that no other domains are referencing the
assembly so it now removes it from the shared domain.

Can someone explain this to me.

Nov 17 '05 #1
1 1909
This is by design, assemblies loaded as domain neutral in the "SharedDoma in"
domain cannot be unloaded, and by applying the MultiDomainHost attribute,
you 'hint' the CLR to load all assemblies as domain neutral. All assemblies
loaded domain neutral cannot be unloaded even though all the appdomains
using these assemblies have been unloaded
Note also that there is no code execution in "SharedDoma in", the code is
executed in user appdomains.

Willy.

"BuddyWork" <dh*****@bankof ny.com> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
I think I've found a possible issue with .Net AppDomain.Unloa d when
using attribute LoaderOptimizat ion.MultiDomain .

Here you will need ProcessExplorer from SysInternals to see what
assemblies are loaded for a given process.

You will need to add the following code into HelloWorld1.cs and compile
through the CS compiler. csc HelloWorld1.cs

// C# Sample Code
// File: HelloWorld1.cs

using System;
using System.Threadin g;

public class HelloWorld
{
public void SayHello(String greeting)
{
Console.WriteLi ne("In the application domain: " +
Thread.GetDomai n().FriendlyNam e);
Console.WriteLi ne(greeting);
}

public static void Main( String[] argv )
{
HelloWorld o = new HelloWorld();
o.SayHello("Hel lo World!");
}
}

You will need to add the following code into ExecAssembly.cs and
compile through the CS compiler. csc ExecAssembly.cs
// C# Sample Code
// File: ExecAssembly.cs
// Creates a remote application domain and executes an assembly
// within that application domain.

using System;
using System.Reflecti on;
using System.Runtime. Remoting;

public class ExecAssembly
{
// By un-commenting the line below causes the problem.
//[LoaderOptimizat ion(LoaderOptim ization.MultiDo main)]
public static void Main( String[] argv )
{
// Set ApplicationBase to the current directory
AppDomainSetup info = new AppDomainSetup( );
info.Applicatio nBase = "file:///" +
System.Environm ent.CurrentDire ctory;

// Create an application domain with null evidence
AppDomain dom = AppDomain.Creat eDomain("Remote Domain", null, info);

// Tell the AppDomain to execute the assembly
dom.ExecuteAsse mbly("HelloWorl d1.exe");

// Clean up by unloading the application domain
AppDomain.Unloa d(dom);
Console.WriteLi ne("HelloWorld 1 UnLoaded");
int i = Console.Read ();
}
}

Now run the ExecAssembly.ex e and while the message HelloWorld1.Unl oaded
is displayed check through ProcessExplorer and you will notice the EXE
HelloWorld1.exe is not listed.

Now un-comment the line
[LoaderOptimizat ion(LoaderOptim ization.MultiDo main)] in module
ExecAssembly.cs and recompile the code. csc ExecAssembly.cs

Now run the ExecAssembly.ex e and while the message HelloWorld1.Unl oaded
is displayed check through ProcessExplorer and you will notice the EXE
HelloWorld1.exe now listed.

The problem is this the framework is not unloading the assembly because
its hold in the shared domain, I thought the shared domain would be
intelligent enough to know that no other domains are referencing the
assembly so it now removes it from the shared domain.

Can someone explain this to me.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2360
by: Chris Lacey | last post by:
Hi, I'm currently writing a scheduling service which starts a number DotNet executables, each within a new AppDomain, every ten seconds. The guts of the code is as follows: // For each executable in the list of tasks for (int i = 0; i < this.processTasks.Length; i++) {
4
6123
by: Mirano | last post by:
Hi everybody. I load an assembly into another AppDomain, not a default one. As there is no way to unload the assembly, I need to unload the domain. This is where the app hangs. The problem is this assembly has references to one dll, currently not performing any work. I tried this: 1. Setting the assembly to null, 2. Implementing a ClassFactory and returning an interface of the object,
2
10856
by: Lauren Hines | last post by:
Hello, I have read numerous post stating that the only way to unload an assembly (DLL in my case) is to create a separate AppDomain, load the assembly, then unload it by calling AppDomain.Unload. When trying to delete the DLL file I get an exception that access is denied. When trying to copy over the DLL file, I get an exception that it is being used by another process.
6
8210
by: Wal Turner | last post by:
Hi there. There are various snippets on forums regarding issues with AppDomain.Unload and how it just doesnt work. Fortunately, I got it working with the base case, after much fiddling. Consider this 5 line program: AppDomain domain = AppDomain.CreateDomain("MyDomain"); domain.CreateInstance("TempDLL", "TempDLL.Class1"); MessageBox.Show("try deleting file now"); //cant delete file AppDomain.Unload(domain);
22
3839
by: JPSutor | last post by:
when I use the AppDomain.UnLoad method (which calls the Thread.Abort method), I get the following error message AppDomain can not be unloaded because the thread 1378 can not be unwound out of it It seems to take time doing this. If I wait for about 30 seconds, it seems to get unloaded. Any ideas?
3
2621
by: Tao | last post by:
hi.. group, A wired question about FileSystemWatcher and Unload an AppDomain. I have a class A which creates class B. When B is created, B loads an AppDomain and execute some functions on the load AppDomain. B monitors disk to see if some files chang. If some file changes, B will try to unload the AppDomain it loaded before.
2
5563
by: Tim | last post by:
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)".
3
1960
by: =?Utf-8?B?QS4gUm9iaW5zb24=?= | last post by:
We are seeing an error in our SQL Server logs I'm not very familiar with, and was hoping someone on her ecould shed some light on the subject... I installed the SS DBA Dashboard on one of our boxes. This box is a 64 bit Windows Server 2003, SP2 running SQL Server 2005 64 bit, Service PAck 2 with Cumulative Update 3 applied. The entire box has 16GB or RAM and 16 processors. We have 12GB of RAM devoted exclusively to SQL Server, which is...
0
1188
by: =?Utf-8?B?QS4gUm9iaW5zb24=?= | last post by:
We are seeing an error in our SQL Server logs I'm not very familiar with, and was hoping someone on here could shed some light on the subject... I installed the SS DBA Dashboard on one of our boxes. This box is a 64 bit Windows Server 2003, SP2 running SQL Server 2005 64 bit, Service PAck 2 with Cumulative Update 3 applied. The entire box has 16GB or RAM and 16 processors. We have 12GB of RAM devoted exclusively to SQL Server, which is...
0
9793
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11151
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10419
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9577
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5804
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5996
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4619
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4225
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.