dll file is getting locked even after the domain in which it is loaded is unloaded

hi,
i am having a problem with dyanmic loading of assemblies.the problem is that the dll file is getting locked even after the domain in which it is loaded is unloaded.The code below shows a dll search being loaded in domain appdomain.then we get a specific type from the dll and unload the domain thereafter.

Now if we want to replace the search dll or delete it ,it is shown as being used and hence can't be deleted.

But unloading a domain should have made it free.Does anyone have a solution for this behaviour .please help.code is as follows
===============================
AppDomain appdomain = AppDomain.CreateDomain("loader domain");


Type t =appdomain.Load(@"Search").GetType("Search.Component");

AppDomain.Unload(appdomain);
===============================================

i could have used shadow property but then i am unloading the domain hosting it so there should be no reference to it in the memory

regards,
ramneek

[1001 byte] By [ramneek] at [2007-12-16]
# 1
I haven't used the appdomain stuff for a little while, but I'm sure it will keep the oringal appdomain open if you have any variable that contains references from that original appdomain.
In your example you've got a type object that you are holding on to, and that maybe preventing the unload from occuring.
Try saving the type name to a string instead and see if the problem goes away.
Steve
Steve_W at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...
# 2
It actually is a bit more complicated than that. When you access a type from the Search assembly, the assembly gets loaded in the calling appdomain also.

The right way to do this is to write a custom RemoteLoader class (a MarshalByRefObject derived class) that will be loaded by both appdomains and use that class to do all the loading stuff for you. In your example, instead of getting the Search.Component type, you'll be getting the RemoteLoader class and then invoke methods on the RemoteLoader to load other classes in the other appdomain.

senthilkumar at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Base Class Library...

.NET Development

Site Classified