Groups | Blog | Home
all groups > c# > october 2006 >

c# : Unloaded Assembly still occours in parent AppDomain


Basti
10/31/2006 11:48:15 PM
Hello,
I'm working with .Net 2.0. I tried to get attributes of an unloaded
assembly. So, the sole way I know is to create a new child application
domain, in this app domain I load the assembly, read out the
attributes, and unload the child app domain. But in this moment, I load
the assembly into the child app domain, the assembly occurs in the
parent app domain, too. And after unloading the child app domain the
assembly is still loaded in the parent domain. Have anybody an idea?

Here is my code:


static void Main(string[] args)
{
foreach (Assembly ass in
AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(ass.FullName);
}

Console.WriteLine("------------------------------------------------------------------------------");
AppDomain domain = AppDomain.CreateDomain("ChildDomain");
domain.Load("TestAssembly");
foreach (Assembly ass in domain.GetAssemblies())
{
Console.WriteLine(ass.FullName);
}

Console.WriteLine("------------------------------------------------------------------------------");
foreach (Assembly ass in
AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(ass.FullName);
}

Console.WriteLine("------------------------------------------------------------------------------");
AppDomain.Unload(domain);
foreach (Assembly ass in
AppDomain.CurrentDomain.GetAssemblies())
{
Console.WriteLine(ass.FullName);
}
Console.ReadLine();
}



Thx
Michael Nemtsev
11/2/2006 1:06:02 AM
If you look in msdn and read about AppDomain.Load you will find that this
method can load your assembly into default domaim inadvertently, because your
can end up that your assembly marshaled by value (not by ref)

I recommend you to use AppDomainManager to load your assemblies
--
WBR,
Michael Nemtsev :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche




[quoted text, click to view]
AddThis Social Bookmark Button