Only managed memory is isolated between AppDomains. If a thread throws an exception in any AppDomain application, this will cause the entire application to crash.
I think the best solution is to ensure that all exceptions are handled properly for each thread (or thread pool work items).
However, there is a hack that consists of applying this configuration in the App.Config file:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <legacyUnhandledExceptionPolicy enabled="1"/> </runtime> </configuration>
Unhandled exceptions will crash the process with .Net 2.0, but you can revert to the old policy using this trick.
I would use this with caution, as it is often best to let processes crash rather than fail. You can add traces to AppDomain.UnhandledException to receive notifications when an unhandled exception occurs and processes them accordingly.
EDIT
You are right about the StackOveflowException, since .Net 2.0 this exception cannot be handled by user code. (See the "Notes" section of this page in msdn ).
There is a way to override this by creating a custom CLR host, but this seems like a crazy thing. I think you have to live with it, or you can create a child process instead of AppDomain if you really need such fault tolerance.
Jeff cyr
source share