How to create a reliable add-in with UI?

Jul 11, 2008 at 8:10 AM

It’s hard to build a reliable add-in with UI and the hardest one is unhandled UI exception.

Image a Tool Window add-in.

The frame of Tool Window is constructed by host with dock ability. The content of it is in add-in side and is exposed to 3<SUP>rd</SUP> parties to be customized. The quality of 3<SUP>rd</SUP> party’s code is out of control and there are some unhandled exceptions hidden in their code, especially UI exception . How can I do?

As we known, there are 3 ways to activate add-ins:

1.       Host’s appdomain;

2.       Its own appdomain;

3.       Other process.

The first 2 approaches can’t help me. If a UI exception is thrown, e.g.: during Click event handler, I can’t know it is an add-in exception and, as a result, the whole application will crash.

So I try the 3<SUP>rd</SUP> and last one. At the beginning, everything seems OK. I can subscribe unhandled exception event handler of Application and do some cleaning up code, if User Control throws some UI exceptions and shut down AddInProcess gracefully. But I find that I can’t create Tool Window from add-in side anymore in the case. L

When I call back form add-in to create a Tool Window, because I am call from an external process, the host will fetch a thread from thread pool to create the Tool Window. Any threads from thread pool are MTA thread and can’t create UI components at all. I almost fall in a faint and can’t believe it.

I check with Visual studio. Visual studio loads add-in into its own appdomain and UI exception form add-in will crash Visual studio, too.

I hope I am misunderstanding on this topic and can get the right answer here.

Jul 11, 2008 at 8:12 AM
Edited Jul 11, 2008 at 8:22 AM
More detail information: I leared the 3<SUP>rd</SUP>  way from the following URL:
http://forums.msdn.microsoft.com/en-US/wpf/thread/3c8592f2-14a6-418b-ab11-6d18096aaa0c