none
Unhandled exceptions in child AppDomains RRS feed

  • Question

  • When creating an application based on plug-in architecture, is that possible to code it such that exceptions in plug-ins do not bring the whole application down.

    One way that comes to mind is to load each plug-in in a separate AppDomain. Then, the expectation is that if a thread in that child AppDomain throws an unhandled exception, there should be some kind of way to unload the child AppDomain without bringing the whole application down.

    But, after searching on the Internet, I can't find a clear answer on how to do that. I see severals posts dated around 2006 on the topic, but the best answer there is to log errors in the AppDomain.UnhandledExcpetion and then, after restart of the entire application, prompt a user with what to do next with offending plug-ins. That's not going to work for me -- I am creating a server-side application that has to stay up when plug-ins fail.

    Would you know the answer on how to keep the main AppDomain running when there is an unhandled exception in a child AppDomain?

    Thanks.


    Evgueni Tsygankov
    Friday, February 18, 2011 8:29 PM

Answers

  •  

    In .NET 2.0, most of unhandled exception will result in termination of the whole process, but we may  enable legacyUnhandledExceptionPolicy option to let the runtime use unhandled exception policy of .NET1.0/1.1, and hence prevent the whole process from being killed by an unhandled exception:

     

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

      <runtime>

        <legacyUnhandledExceptionPolicy enabled="1"/>

      </runtime>

    </configuration>

     

    You can also use ICLRPolicyManager::SetUnhandledExceptionPolicy method to specify the behavior of the common language runtime (CLR) when an unhandled exception occurs.

     

    Read more details from: Exceptions in Managed Threads


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 22, 2011 2:51 AM

All replies

  •  

    Hi Evgueni,

     

    My test result shows that an unhandled exception of child AppDomain will be escalated as an exception of Default AppDomain, if Default AppDomain didn't handle this exception, a new unhandled exception occurs, and then the whole process will be terminated.

     

    I'm looking for a way to restrict unhandled exception in AppDomain level, will let you know as soon as I find anything.


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 21, 2011 10:26 AM
  •  

    In .NET 2.0, most of unhandled exception will result in termination of the whole process, but we may  enable legacyUnhandledExceptionPolicy option to let the runtime use unhandled exception policy of .NET1.0/1.1, and hence prevent the whole process from being killed by an unhandled exception:

     

    <?xml version="1.0" encoding="utf-8" ?>

    <configuration>

      <runtime>

        <legacyUnhandledExceptionPolicy enabled="1"/>

      </runtime>

    </configuration>

     

    You can also use ICLRPolicyManager::SetUnhandledExceptionPolicy method to specify the behavior of the common language runtime (CLR) when an unhandled exception occurs.

     

    Read more details from: Exceptions in Managed Threads


    Eric Yang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, February 22, 2011 2:51 AM