By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,107 Members | 1,484 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,107 IT Pros & Developers. It's quick & easy.

Unloaded Assembly still occours in parent AppDomain

P: n/a
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

Nov 1 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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


"Basti" wrote:
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

Nov 2 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.