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.

Monday, 21 December 2009

Experiment in persistence ignorance

Having read a lot about how cool NHibernate is in helping with persistence ignorance, I decided to check if I can go far enough with it. More precisely, I decided to check if I can live without the Id property on my entities.

Now, you might ask, how do I show say products of a particular category. I mean, if I have a Web site, there should be some Url for it, and this Url should look like Products.aspx?CategoryId=1 or Products/List/CategoryId/1, whatever, but you should include the Id somehow. The answer is, you can always use session.Get() or session.Load() to get the entity by its Id, and the reverse is also true: you can use session.GetIdentifier() to retrieve the entity's Id.

At the same time, I switched from entities to models in my pages (WebForms or MVC). Doing this was a big relief because I felt myself dirty when adding a lot of properties to my entities just for the purpose of viewing (like, CategoryName, ItemCount etc). On the other hand, it means a lot of additional boring work: creating model classes and adding the mapping code. Fortunately, the first task is easy with the help of T4 templates, while the second is what AutoMapper (and other mappers) is created for.

Long story short, even though I managed to automate a lot, including the custom mapping code, I still got a lot of places where I had to repetively write session.GetIdentifier() in order to retrieve the Id. So, I'd recommend leaving it in place, although it doesn't seem to make much sense in terms of my domain.

Disclaimer: by entities, models and stuff I don't want to say that I'm doing DDD or any other cool stuff. The system is too simple for that. Nevertheless, separating models from entities, provided it doesn't require much effort, pays off in my case.

Monday, 13 July 2009

Interacting with embedded Flash content in Flex

I've been doing some Flex development lately (sorry Microsoft), so I though I might share a little discovery of mine in return to numerous advices from the community.

While creating a complex Flash application, it is a common situation that the graphical content and animations created by designers in Flash, while developers load them into a Flex application. While loading is pretty straightforward, often you need to manipulate them, i.e., play a different clip, detect then a clip reaches a certain label, etc. What you usually do is have your flash content have a certain base class (called Document class) which is known to your flex app, and cast loader.content to this class once it's loaded.

The problem is, the above solution doesn't work with embedded content. Don't know whether it is a bug or a feature, but the content cannot be cast to the document class. The docs say, use embedded content for static stuff like images or static swfs. Well, my content was an intro to a module, and I had to detect it's finished playing in order to hide it and show the actual content. On the other hand, I wanted it embedded so that my preloader would work correctly. In addition, the module had a base class, and I wanted to have the intro-related code in the base class, while embedding the intro into the actual module.

So, utilizing some hints from the community plus a little debugging session, and here's my solution (I still don't see any reason why it works this particular way).

  1. Embed the flash content via the metadata tag:
    [Embed(source="../../flex_bin/someflash.swf", mimeType="application/x-shockwave-flash")]
    private var SWFBytes:Class;
  2. Use it in your SWFLoader (note the source):
    <mx:swfloader id="introLoader" source="{new SWFBytes()}" scalecontent="false" creationcomplete="intro_complete(event)">
  3. Handle the CreationComplete event like this:
    var content:MovieClip= this["introLoader"].content as MovieClip;
    var loader:Loader = content.getChildAt(0) as Loader;
    var intro:RoomIntro = RoomIntro(loader.content);
Here's the "intro" variable we're interested it, RoomIntro is the document class of the flash movie. Note that the content of our loader is a movie clip, but it's not what we need: it has a child, which is another loader, and the content of *this* loader is what we actually need. In short, we need the content of the first child of the content of our loader.

Tricky, eh?

Tuesday, 19 May 2009

Get a free TypeMock Isolator + Ivonna

Unit Testing ASP.NET? ASP.NET unit testing has never been this easy.

Typemock is launching a new product for ASP.NET developers – the ASP.NET Bundle - and for the launch will be giving out FREE licenses to bloggers and their readers.

The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both Typemock Isolator, a unit test tool and Ivonna, the Isolator add-on for ASP.NET unit testing, for a bargain price.

Typemock Isolator is a leading .NET unit testing tool (C# and VB.NET) for many ‘hard to test’ technologies such as SharePoint, ASP.NET, MVC, WCF, WPF, Silverlight and more. Note that for unit testing Silverlight there is an open source Isolator add-on called SilverUnit.

The first 60 bloggers who will blog this text in their blog and tell us about it, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator + Ivonna). If you post this in an ASP.NET dedicated blog, you'll get a license automatically (even if more than 60 submit) during the first week of this announcement.

Also 8 bloggers will get an additional 2 licenses (each) to give away to their readers / friends.

Go ahead, click the following link for more information on how to get your free license.