h1

Hello,

I was under the impression that an exception inside the appdomain doesn't cross the appDomain. But it is not happening for me.

Here is my setup:

My default app domain contains an EXE (container).

The container creates a new appDomain (newAD).

The container adds an event handler for newAD.UnhandledException

the container loads an assembly into the newAD.

the container invokes MyClass o = newAd.CreateInstanceAndUnwrap(...)

the container invokes a method on the instance o.PleaseThrowAnException();

the method throws an exception and kills the container appdomain.

I was expecting the exception to get handeled by the event handler for newAd.UnhandledException.

Could someone help me figure this out

Thanks



Re: Visual C# General Appdomain - Exception Management

Friendly Dog

In my understanding, the exception will not be thrown back. This is one of the benifits of using AppDomain - to isolate tasks that may bring down a process. The CreateInstanceAndUnwrap gives you a proxy that calls into the hosted AppDomain. When you say "PleaseThrowAnException" through the proxy, the actual action takes place within the hosted AppDomain.




Re: Visual C# General Appdomain - Exception Management

h1

So How can I make sure that the "PleaseThrowAnException" happens in the newly created AppDomain

Thanks.





Re: Visual C# General Appdomain - Exception Management

Friendly Dog

I believe the exception does happen in the newly created domain, you can try to log a message to event log or a file to verify this.