2

I have WPF host app and AddIn is also WPF which returns UI as described below:

[link] http://msdn.microsoft.com/en-us/library/bb909849%28v=vs.110%29.aspx

I would like to know if it is even possible to activate WPF AddIn as external process:It looks like WPF add-ins have only been thought to be used with AppDomain isolation, which is just not good enough for our app. If AddIn crashes for any reason, we can't allow host to crash all the time. We want our host app to be running even if loaded AddIn crashes.

I know we can achieve this in System.AddIn by using following:

//Activate the selected AddInToken in a new 
//application domain with the Internet trust level.
Calculator CalcAddIn = selectedToken.Activate<Calculator>(new AddInProcess(), AddInSecurityLevel.fulltrust);

But I have WPF AddIns not System.AddIn because our AddIns have WPF UI components.

I can activate WPFAddIn in new app domain as follows:

//Activate the selected AddInToken in a new 
//application domain with the Internet trust level.
Calculator CalcAddIn = selectedToken.Activate<Calculator>(AddInSecurityLevel.Internet);

I could not get any any up-to-date information about handling this situation with WPF AddIns. Is there any possible example either how to activate WPF AddIn in a separate process or catch unhandled exceptions in host. Basically I can't allow host to die when addIn crash. I did follow following link but turned out thread is very old and there is no current information.

[link]http://social.msdn.microsoft.com/Forums/vstudio/en-US/3c8592f2-14a6-418b-ab11-6d18096aaa0c/systemaddin-addinprocess-and-wpf?forum=wpf

If I can handle exception in host that will be fine too. Let me explain my problem:

I have WPF Host "A". have WPF AddIn "B".

I have loaded AddIn "B" in Host "A". AddIn "B" is having a click button. When user clicks a button, event will be fired in AddIn "B". In that event no try catches available, and some null exception is thrown from that event. This unhandled exception causing my host (WPF app as well) to crash.

I am looking for a solution, where I can handle this exception in Host "A", unload the AddIn "B" and continue Host without any crash.

I have tried AddIn with AddInSecurityLevel.FullTrust as well as AddInSecurityLevel.Internet.

Any hints or example will be helpful.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
user2506411
  • 303
  • 1
  • 5
  • 10
  • Instead of adding all this complexity (MAF) you could monitor the add-ins that crash your app and if they crash too often blacklist them. Then allow the user to enable the unstable plug0in. This is the approach of MS OFFICE (http://office.microsoft.com/en-us/outlook-help/enable-or-disable-add-ins-in-office-programs-HA010034127.aspx#BM1). – Panos Rontogiannis Jan 27 '14 at 09:03
  • Hi Panos- I am already using MAF (WPF AddIn) pipeline approach to load plugins. Is there any way to prevent crash in this MAF-WPF AddIn approach. Because we can't run WPF AddIns in separate process. – user2506411 Jan 27 '14 at 17:46
  • AppDomain isolation cannot guarantee this. Under some circumstances it can but not completely. Have a look at http://stackoverflow.com/a/16438141/850119. In your case of course you can't have process isolation. But the rest applies. – Panos Rontogiannis Jan 28 '14 at 07:45

1 Answers1

5

I think following msdn magazine article clearly explains how to design fault tolerant plugging based applications where plugins are hosted in separate process. It has a sample too. In the sample, addins' exceptions are handled easily without impacting host application or other addins.

Build Fault-Tolerant Composite Applications in WPF http://msdn.microsoft.com/en-us/magazine/dn519924.aspx

Praggie
  • 396
  • 2
  • 12
  • Praggie- Thanks for the reply. I will give a try and report back results. – user2506411 Jan 27 '14 at 17:46
  • 1
    I endup using "Build Fault-Tolerant Composite Applications in WPF" for our application. It works perfectly fine according to our needs. If plugin crash for any reason -host app did not crash. Because plugin is running in its separate own process. Plugin load/initialization is way faster than MAF/WPF AddIn. – user2506411 Jan 29 '14 at 21:04
  • the link to the article is broken, I found this article, not sure if it is the same as in the original answer https://learn.microsoft.com/en-us/archive/msdn-magazine/2014/january/wpf-build-fault-tolerant-composite-applications – Moustafa Khalil Aug 19 '23 at 04:45