AppDomain.Unload

G

Guest

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 this assembly has references to one dll, currently not
performing any work.
I tried this:
1. Setting the assembly to null,
2. Implementing a ClassFactory and returning an interface of the object,
then removing it,
3. Making assembly to implement the IDisposable interface.

None of this works. All examples on the Net just shows how to create
AppDomains, load assemblies and then unload the AppDomain. None of those show
what happens if the assembly has referenced assemblies.

Thank you for your help.
 
D

Daniel O'Connell [C# MVP]

Mirano said:
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 this assembly has references to one dll, currently not
performing any work.
I tried this:
1. Setting the assembly to null,
2. Implementing a ClassFactory and returning an interface of the object,
then removing it,
3. Making assembly to implement the IDisposable interface.

None of this works. All examples on the Net just shows how to create
AppDomains, load assemblies and then unload the AppDomain. None of those
show
what happens if the assembly has referenced assemblies.

What do you mean by referenced assemblies? Are you sure the problem is due
to a assembly reference and not something else?
 
D

David Levine

Simply having one assembly reference another assembly does not do
anythything...code must get executed so that the JIT loads the referenced
assembly. e.g. if one assembly references a type defined in the other
assembly, even if no methods are called, the referenced assembly will get
loaded. Further, you can only hang on unloading an appdomain if a thread
with stack in the doomed appdomain calls out to unmanaged code and the call
never returns.

So if you are really experiencing a hung app when the appdomain unloads
there must have been a whole lot more going on then what you are telling us.
 
G

Guest

Yes, of course I go Activator.CreateInstance and load the main assembly,
while the main assembly (for now) just creates the object of the referenced
assembly (which is simply a dll) not calling any methods.
No unmanaged code is accessed anywhere.
These assemblies will perform some tasks that the main service will never
know about, it is used to just start them off, so I can not use some manager
service to get into the AppDomains and manage the execution.
The problem is why this unloading of the AppDomain hangs the application,
when unloading of the AppDomain with a single assembly works just fine.
The situation will get even worse when there will be more assemblies that
the main assembly references and uses, and when those assemblies start to do
some work, creating the threads on their own, etc... when even this simple
setup with a main assembly and one referenced assembly does not work.
This is corrected in .Net 2.0 when unloading works just fine, and you can do
a lot more there, but I build under 1.1 Framework

Thanks.
 
D

David Levine

Without more information I cannot begin to tell why your app is hanging. I
create and unload appdomains all the time without experiencing the problem
you are having. I do it from applications, window services, web services,
component libraries, etc.without it hanging. I currently do all my
development using the 1.1 framework, so if mine works so should yours.

Does this problem occur with any referenced assembly or only a specific one?
 

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