ASP.NET MVC JsonResult on Mono and the JavaScriptSerializer

I have been doing a little work on an ASP.NET MVC solution on Visual Studio and Windows and then a little later i moved it to MonoDevelop on OS X to continue development. Opening the Visual Studio solution file in MonoDevelop just works and compiling the code has no issues, however running it I got the following exception:

Cannot cast from source type to destination type.

System.InvalidCastException: Cannot cast from source type to destination type.
  at System.Web.Script.Serialization.JavaScriptSerializer..ctor (System.Web.Script.Serialization.JavaScriptTypeResolver resolver, Boolean registerConverters) [0x0000d] in /private/tmp/monobuild/build/BUILD/mono-2.10.8/mcs/class/System.Web.Extensions/System.Web.Script.Serialization/JavaScriptSerializer.cs:66 
  at System.Web.Script.Serialization.JavaScriptSerializer..cctor () [0x00000] in <filename unknown>:0 

After a little investigation I found that it is mixed up DLL's causing this. You can see on the screenshot below two versions of System.Web.Extensions.dll is loaded both 3.5 and 4.0.

System.Web.Extensions loaded twice in two different versions

The reason for this seems to be that the System.Web.Mvc.dll is compiled referencing the 3.5 version and not the 4.0 version so we can easily fix this with a redirect using assemblyBinding element in our web.config:

<runtime>
	<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
		<dependentAssembly>
			<assemblyIdentity name="System.Web.Extensions" culture="neutral" publicKeyToken="31bf3856ad364e35" />
			<bindingRedirect oldVersion="3.5.0.0" newVersion="4.0.0.0"/>
		</dependentAssembly>
	</assemblyBinding>
</runtime>

And that should make you able to proceed with your ASP.NET MVC development with Mono

UPDATE: This is already reported as a bug describing the workaround aswell: https://bugzilla.novell.com/show_bug.cgi?id=664813

Posted on 18 Jan 2012 by Jakob T. Andersen

Generating static blog using Mono's LameBlog

This blog is generated using Mono LameBlog a tool created by Miguel de Icaza to run his own blog. I stumpled upon it in the mono source tree a couple of years back when i was doing some work with Mono. Without offending anyone I think you can say that LameBlog is not a polished piece of software, but it is actually very convinient for a couple of reasons:

  • Blogentries in your favorite VCS
  • Easy offline editing with your favorite editor
  • Simple hosting setup, only needs to support basic HTML
  • Scalable as it is only HTML

It works by generating the whole site structure from a predefined format of entries stored on your local disk, to do this it uses a template and a configuration file which you can use to tweak apperance (I didn't do this much as you can see). Furthermore the deployment process is hidden in the makefile of the projects and utilizes rsync to push changes to the server.

So to sum up the workflow this it how it looks like when i write a blog post:

vim ~/Activity/2012/jan-16.html
#Write the blog post using HTML and small #-prefixed lines for imagehandling etc
cd Projects/lb
make push

Note that i have my posts stored in VCS but commands not included above.

To make the interactive features of a common blog like commenting and search work third party providers is used, namely a Disqus and a Custom Google Search, its a little bit of an experiment and primarily aimed at making blogging so convenient as possible for me so i might do it more often, but we have to see.

Currently this site is hosted on a free-usuage-tier EC2 micro instance at Amazon with an nginx webserver

Posted on 16 Jan 2012 by Jakob T. Andersen