Assembly not getting unloaded

A

Ashutosh

Hi,
I have this simple code
AppDomain d = AppDomain.CreateDomain("test123");
Assembly a = d.Load("ClassLibrary1, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=c4510fb7f9c15154");
MethodInfo m = o.GetType().GetMethod("Hello");
m.Invoke(o, null);
AppDomain.Unload(d);

after the Unload statement, the ClassLibary1 is still loaded into the
process address space. How can I make sure that it's unloaded?

Thanks & Regards,
Ashutosh
 
A

Ashutosh

Oops!! missed this line
object o = a.CreateInstance("ClassLibrary1.TestClass123");

it should be after the d.Load method call.....
 
J

Jeffrey Tan[MSFT]

Hi Ashutosh ,

Yes, I can reproduce this issue. Even though you are loading the assembly
in the context of the new appdomain, you are returning a reference to it in
the default appdomain, which causes it to load the assembly in both
appdomains. So the assembly will not be unloaded from the process space.
You need to write a class that is remoted back to the default appdomain,
and provide a method, e.g. LoadAndRun() that does the actual loading. The
articles below provide the detailed steps:
"Assembly.Unload? Use AppDomain.Unload instead."
http://codebetter.com/blogs/ranjan.sakalley/archive/2005/04/08/61574.aspx
"Dynamic Plugins: Using the AppDomain Class to Load and Unload Code"
http://www.devsource.com/c/a/Using-VS/Dynamic-Plugins-Using-the-codeAppDomai
ncode-Class-to-Load-and-Unload-Code/

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=========================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top