473,320 Members | 2,177 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,320 software developers and data experts.

Possible Buy/Issue with AppDomain.UnLoad

I think I've found a possible issue with .Net AppDomain.Unload when
using attribute LoaderOptimization.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.Threading;

public class HelloWorld
{
public void SayHello(String greeting)
{
Console.WriteLine("In the application domain: " +
Thread.GetDomain().FriendlyName);
Console.WriteLine(greeting);
}

public static void Main( String[] argv )
{
HelloWorld o = new HelloWorld();
o.SayHello("Hello 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.Reflection;
using System.Runtime.Remoting;

public class ExecAssembly
{
// By un-commenting the line below causes the problem.
//[LoaderOptimization(LoaderOptimization.MultiDomain)]
public static void Main( String[] argv )
{
// Set ApplicationBase to the current directory
AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = "file:///" +
System.Environment.CurrentDirectory;

// Create an application domain with null evidence
AppDomain dom = AppDomain.CreateDomain("RemoteDomain", null, info);

// Tell the AppDomain to execute the assembly
dom.ExecuteAssembly("HelloWorld1.exe");

// Clean up by unloading the application domain
AppDomain.Unload(dom);
Console.WriteLine("HelloWorld1 UnLoaded");
int i = Console.Read ();
}
}

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

Now un-comment the line
[LoaderOptimization(LoaderOptimization.MultiDomain)] in module
ExecAssembly.cs and recompile the code. csc ExecAssembly.cs

Now run the ExecAssembly.exe and while the message HelloWorld1.Unloaded
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 1887
This is by design, assemblies loaded as domain neutral in the "SharedDomain"
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 "SharedDomain", the code is
executed in user appdomains.

Willy.

"BuddyWork" <dh*****@bankofny.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
I think I've found a possible issue with .Net AppDomain.Unload when
using attribute LoaderOptimization.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.Threading;

public class HelloWorld
{
public void SayHello(String greeting)
{
Console.WriteLine("In the application domain: " +
Thread.GetDomain().FriendlyName);
Console.WriteLine(greeting);
}

public static void Main( String[] argv )
{
HelloWorld o = new HelloWorld();
o.SayHello("Hello 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.Reflection;
using System.Runtime.Remoting;

public class ExecAssembly
{
// By un-commenting the line below causes the problem.
//[LoaderOptimization(LoaderOptimization.MultiDomain)]
public static void Main( String[] argv )
{
// Set ApplicationBase to the current directory
AppDomainSetup info = new AppDomainSetup();
info.ApplicationBase = "file:///" +
System.Environment.CurrentDirectory;

// Create an application domain with null evidence
AppDomain dom = AppDomain.CreateDomain("RemoteDomain", null, info);

// Tell the AppDomain to execute the assembly
dom.ExecuteAssembly("HelloWorld1.exe");

// Clean up by unloading the application domain
AppDomain.Unload(dom);
Console.WriteLine("HelloWorld1 UnLoaded");
int i = Console.Read ();
}
}

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

Now un-comment the line
[LoaderOptimization(LoaderOptimization.MultiDomain)] in module
ExecAssembly.cs and recompile the code. csc ExecAssembly.cs

Now run the ExecAssembly.exe and while the message HelloWorld1.Unloaded
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
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...
4
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...
2
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....
6
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...
22
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...
3
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...
2
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...
3
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...
0
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.