Probably a copy of: Can I prevent an uncaught exception in another AppDomain from shutting down the application?
Been trying all day to figure out the answer to this question.
Just want to make sure that the answer is indeed no, before I throw away all the code Ive made to isolate my drivers inside their separate appdomains and replace it with old-school processes.
So the formal question is this.
Having a default domain "ad-default", in which I create a new appdomain "ad-hosted", can I avoid that unhandled exceptions from "ad-hosted" tears down "ad-default"?
I am aware that I can observe the exceptions by hooking up to the UnhandledException event of the "ad-hosted" domain, but I can find no way to stop them from propogating to the "ad-default" domain.
Is this really true? But why would we even want AppDomain's, if they do not provide isolation?
EDIT: The answer is unfortunately NO, see this answer for explanation: AppDomain, handling the exceptions
The only way to isolate the exceptions in a thread in another appdomain from tearing down the default domain is to use:
<runtime>
<legacyUnhandledExceptionPolicy enabled="1"/>
<runtime>
Which will set IsTerminating flag of the unhandledexception to false, and prevent the default domain from shutting down.
What we did in our case was to hook up to the UnhandledExceptionHandler in both domains. We then trigger a semafore in in the "ad-hosted" that will be picked up by a thread created for this purpose in "ad-default", which then in turn disposes the "ad-hosted"
This is a hack and will probably not survive into future generations of the framework, but it makes "ad-default" more robust, in that it will not be torn down on unhandled exceptions in the "ad-hosted"
we also hook up a eventhandler in "ad-default" that will cast sender as appdomain and check if the exception originated in "ad-default", if so we tear down the "ad-default" too, emulating the behavior of .net 2.0, even with the runtime setting described above.
Hope this gives somebody a clue on how to make a more resilent plugin host.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With