364,085 Members | 5185 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

AppDomain.Unload

Mirano
P: n/a
Mirano
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.
Oct 11 '05 #2
Share this Question
Share on Google+
4 Replies


Daniel O'Connell [C# MVP]
P: n/a
Daniel O'Connell [C# MVP]

"Mirano" <Mirano@discussions.microsoft.com> wrote in message
news:EE89CE28-43A4-4D7D-AE7D-5CAC60147DC0@microsoft.com...[color=blue]
> 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.
>[/color]

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


Oct 11 '05 #1

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

"Mirano" <Mirano@discussions.microsoft.com> wrote in message
news:EE89CE28-43A4-4D7D-AE7D-5CAC60147DC0@microsoft.com...[color=blue]
> 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.[/color]


Oct 11 '05 #3

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

"David Levine" wrote:
[color=blue]
> 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.
>
> "Mirano" <Mirano@discussions.microsoft.com> wrote in message
> news:EE89CE28-43A4-4D7D-AE7D-5CAC60147DC0@microsoft.com...[color=green]
> > 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.[/color]
>
>
>[/color]
Oct 11 '05 #4

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

"Mirano" <Mirano@discussions.microsoft.com> wrote in message
news:50F3ADB3-F2E5-44D6-957E-64B8C537F86B@microsoft.com...[color=blue]
> 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.
>
> "David Levine" wrote:
>[color=green]
>> 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.
>>
>> "Mirano" <Mirano@discussions.microsoft.com> wrote in message
>> news:EE89CE28-43A4-4D7D-AE7D-5CAC60147DC0@microsoft.com...[color=darkred]
>> > 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.[/color]
>>
>>
>>[/color][/color]


Oct 13 '05 #5

Post your reply

Help answer this question



Didn't find the answer to your .NET Framework question?

You can also browse similar questions: .NET Framework