Saturday, November 13, 2010

Solving the "File Is Corrupt" Install Error for ASP.NET MVC 3 RC

I was eager to get my hands on the latest version of ASP.NET MVC 3 when my euphoria was abruptly interrupted with an install error.

















HINT: Use Internet Explorer 8 (IE8)...

The problem is client side. Apparently the installer only works if downloaded via IE8. I received the error using Google Chrome and according to Scott Gu, IE9 Beta won't suffice either.  Once downloaded with IE8, you should be able to enjoy the wonders of MVC 3 RC.

NOTE: If you've installed the Async CTP or a previous version of MVC 3, you'll have to uninstall it in order to install MVC 3 RC. See this blog post here from Scott Gu for more details.

Let the hacking begin...
We've all had our problems serializing .NET dictionaries. Specifically with the XmlSerializer. Everyone has saw that dreaded yellow screen of death or perpetual stack trace...

// post stack trace.

Serialization using json

There are 2 choices we have here. The legacy JavaScriptSerializer and DataContractSerializer. The legacy implementation will allow you to serialize more complex data strucutures, but at a cost. Here's the output of the legacy serializer.

// show output.

You may be thinking "no big deal" right?

Well lets take a look at what the DataContractJsonSerializer outputs

// show output.

As you might have guessed, the latter can be more readily consumed client side. It takes the names of the target objects properties into consideration, which is what one would expect.

Wrap up

Use the legacy serializer when you don't care about the output or you want to serialize nested collections without getting yelled at by the runtime.

Use the newer WCF based serializer when you want more user friendly javascript to work with.

The problem with json serialization

Notice that nothing about types when mentioned by the output of neither the legacy or WCF based serializers. That would present itself as a problem for most. In my case, it broke my equality comparison because as we all know, one rudimentary philosophy of equality is that the objects in question must be of the same type.

XmlSerializer to the rescue