Thursday 31 December 2009

ExecutionEngineException in Silverlight 3

I just started playing with Silverlight (you know, waiting for the patform to mature and stuff), plus I've got WCF on the other end, which I'm learning from scratch as well. So, I managed to make a working but messy project, and after that (ok, actually after it stopped compiling) I decided to start from scratch (ok, just copypaste the relevant bits of the working code).

This is when my FireFox started to quietly die instead of showing me the results of the WCF query.

Debugging gave me the exception, and it better didn't. It was the ill-famous ExecutionEngineException, something that, as MSDN itself admits, Should Never Happen. What's worse, the exception was somehow related to a MessageBox. I forgot to mention that I used an evaluation version of some control, and it was displaying a message box spontaneously inviting me to buy the full version. Googling told me that message boxes do cause such issues.

Anyway, the actual problem was that I forgot to configure my service in web.config, so the actual exception was quite different. I was calling the service asynchronously, so the exception happened on a non-UI thread, and it could somehow interfere with the abovementioned message box.

So, my guess is that the exception has been caused by these ingredients, in order of appearance:
  1. a message box;
  2. unhandled exception
  3. on a non-UI thread
  4. possibly, some code in the Application_UnhandledException handler.