1

I have a windows service that uses MAF to load user created plugins. Here is how I am loading each addin:

public bool ActivatePlugin()
{
    try
    {
        _addin = _token.Activate<IAddIn>(AddInSecurityLevel.Host);
        return true;
    }
    catch(Exception ex)
    {
        AddToLog("Error activating plugin");
        return false;
    }
}

All the addins will load ok without any issues. The problem I am having is that I don't have control over the quality of the addins and sometimes they crash and cause the whole service to stop. Is there a way for me to properly catch any errors that come out of the addins so it won't crash the service.

Brian
  • 1,397
  • 9
  • 33
  • 51

2 Answers2

3

Look at these articles from the blog of the System.AddIn team for information on exception handling and add-ins:

http://blogs.msdn.com/b/clraddins/archive/2007/05/01/using-appdomain-isolation-to-detect-add-in-failures-jesse-kaplan.aspx

http://blogs.msdn.com/b/clraddins/archive/2007/05/03/more-on-logging-unhandledexeptions-from-managed-add-ins-jesse-kaplan.aspx

Basically the only way to be safe is to activate the add-in in a separate process. This is easy because MAF provides a way to do so but as you can imagine it is expensive in terms of performance.

Note that activating an add-in in a different application domain does not guarantee that an add-in will not crash the host. The host will crash in case of unhandled exception raised by a thread created by the add-in.

I know this question is a bit old but somebody else could find this information useful.

Panos Rontogiannis
  • 4,154
  • 1
  • 24
  • 29
0

You'll want to load your addins in separate AppDomains or even separate processes. You may also want to use AppDomain.UnhandledException to alert you to a failed addin - it will still fail but you'll be alerted on the way out.

Check out this answer: Good Architecture/Library For Robust Plugin/Addon Management.

Community
  • 1
  • 1
Ed Power
  • 8,310
  • 3
  • 36
  • 42