Reliable Calculator V2 not that reliable?

Aug 16, 2008 at 9:30 PM
Hello AddIn people

I've downloaded the RTM version of the Reliable Calculator V2, and I'm having some trouble seeing how reliable it really is.

Granted, we get an unhandled exception handler for the AppDomain, but as far as I can se, I still get the Exception.. When I run the app in debug mode (Vs.NET 2008) I get an "System.Exception was unhandled", with message: "Exception of type 'System.Exception' was thrown.", after I enter "1 throw 1".
I thought the idea was that we could handle these events?

I get the exception in CalculatorV3AddIn.cs, method ThrowOnChildThread, line: "System.Threading.ThreadStart ts = new System.Threading.ThreadStart(delegate { throw new Exception(); });", where the yellow marker of VS is marking the "throw new Exception();".
I tried to set a breakpoint in the "CurrentDomain_UnhandledException", to see if any exceptions are caught. And they are, but I have no control over the exception happening anyway. Normally I get an option to enter a line "e.Handled = true;" (I know this is not always the case, but it's normal in the rest of .NET with regards to UI developtment...), but I can't do it here. Would that be possible to implement?

If I run the application with no debug (CTRL + F5), the app just crashes when I enter "1 throw 1"...

Can you help?

Regards
Claus Nielsen


Aug 18, 2008 at 8:14 PM
Hi cln,

Unfortunately unhandled exceptions in threads that an add-in spawns can't be handled if you're activating in the same process. What you can do is log the failure in the handler.

Alternately, you can activate the add-in in a separate process, in which case the host process stays up even if the add-in process goes down.
Nov 2, 2008 at 2:51 PM
That would be a good idea, but then I can't use the unhandled exception example you've provided.

The AppDomain i null, when setting up the unhandled exception event handler..

Got any hints?
Nov 19, 2008 at 12:19 AM
Hi cln,

You could use the AddInProcess.ShuttingDown event, or use WaitForExit to detect if the add-in process goes down:
System.Diagnostics.Process.GetProcessById(addInProcess.ProcessId).WaitForExit();
Nov 20, 2008 at 5:42 AM
Hi mSid,

Will the addInProcess.ShuttingDown Event fired when any unhandled exception occurs inside my AddInProcess ?

I had an unhandled exception inside my AddIn Process and the process went down. But the host has subscribed to this ShuttingDown event which was never called.

Any other way to detect an unhandled exception inside my AddInProcess so that i could know the process going down and i can start the AddInProcess again ?
Nov 20, 2008 at 9:29 AM
Hi mSid & AddIn Team,

I wrote the below code in the host app.

AddInController

 

controller = AddInController.GetAddInController(addin);
AppDomain domain = controller.AppDomain;
domain.UnhandledException +=
new UnhandledExceptionEventHandler(domain_UnhandledException);

The host and the addin are in different AppDomains. 
I have an unhandled exception in a AddIn which crashes the Host App.
The unhandled exception in addin never reaches host.

Whats the work around ?



 

Dec 16, 2008 at 11:15 PM
Hi Bhupesh,

Unforunately, unhandled exceptions in the host process will take down the host process, even if the UnhandledException handler is hooked up (this is due to the CLR design)

To really be resilient to unhandled exceptions, you will need to activate out-of-process.

Thanks,
-Mueez