Category Archives: Code

Software Development

Compile & Build Mono on Mac OS X

In spite of what you might still read on, mono source moved to To build and compile on the mac however the simplest instructions are still the “One Stop Shop Build Script” at the bottom of They worked for me first time although I hit a couple of issues:

  1. Having a space in the path to where I built it broke the build script
  2. Fetching the mono repo from git failed several times. This may – or may not – be related to the OS X 10.9 Mavericks / Versions issue noted at but I’ve had no further problems since following their instruction to
    git config --global core.trustctime false

Asp.Net MVC4 C# Razor Template for Mono on Mac and Linux

Is available on (The github download includes all the required dlls in case you don’t have NuGet working, so it’s an oversized download. If you do have NuGet working, you’ll find everything as NuGet expects).

One step to get the MVC4 template working on Mono

Download from github and open the solution in Xamarin Studio. It should almost work out-of-the-box; the one thing you have to do is either do this from the command line:

sudo mkdir /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry
sudo chmod g+rwx /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry

(replacing 3.2.5 with your mono version, which you get at the command line with mono --version);
Or, the alternative to this is to delete the reference to Microsoft.Web.Infrastructure.dll from the project and delete it from the bin directory too.
Small disclaimer: tested on Mac only. If you can offer feedback for Linux/Windows that would be great.

Footnote: How to build the Visual Studio Asp.Net MVC 4 template on Mono

For the interested who have a copy of VS2012, here’s the recipe.

  1. From Visual Studio 2012 create a new Project with the C#-Web-MVC4 Wizard and choose Intranet-Razor-No Unit Test.
  2. Try to run the resulting project on Mono on Mac.
  3. Address the problems arising in the following order
    1. System.UnauthorizedAccessException

      Access to the path “/Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry” is denied. (Where the whole path varies by O/S & 3.2.5 is your mono version).


      sudo mkdir /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry
      sudo chmod g+rwx /Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry

      i.e. allow members of admin group to read/write the registry. Obviously you could widen privileges but this is all that’s needed for

    2. System.TypeLoadException

      Could not load type ‘System.Data.Entity.Migrations.Sql.SqlCeMigrationSqlGenerator’ from assembly ‘EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089’.


      Remove references to Entity framework from THREE places: web.config, Project references AND delete them from the bin directory if they in there:

      • System.Data.Entity
      • System.Web.Entity
      • Entity.Framework
    3. System.TypeLoadException

      Could not load type ‘System.Net.Http.MultipartRelatedStreamProvider’ from assembly ‘System.Net.Http.Formatting …


      add this redirect to the web.config. You should find there are other ‘dependentAssembly’ redirects in there within the section so put it alongside them:

        <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
          <bindingRedirect oldVersion="" newVersion=""/>
    4. And finally … System.Web.HttpException

      Because you don’t have windows authentication available to you when running on Mac or Linux.


      Comment out

      <deny users="?"></deny>

      from the web.config.
      Note that you’re now unsecured. The simplest way to add security back in is to use Forms authentication. If you don’t know how to do this, the simplest start might to look at


Serving Asp.Net MVC4 pages on Mono with xsp. That is, with xsp4

I couldn’t see why the command-line xsp command didn’t work until I realised there is an not-very-well-advertised xsp4. At which point I guess the 2 in xsp2 means .Net 2 rather than, say, xsp version 2. So now I know that:

To run an Asp.Net 4 or 4.5 web application you need xsp4; whereas to run an Asp.Net 2 (or 3 or 3.5) app you need xsp2.

man xsp4 returns nothing, but the switches all seem to be the same as you’ll find with man xsp. So to run your MVC4 web app from the command line, cd to the web app directory and just run xsp4.

Asp.Net MVC 4 on Mono and Windows

Having at last got an Asp.Net Mvc 4 project template working on the Mac/Xamarin/Mono, I came to grief again when deploying it to a Windows hosted server. The problem is that whereas mono works without Microsoft.Web.Infrastructure.dll (and indeed is likely to give errors if you have it), for hosting on Windows you must re-include it.
So my deploy process now includes putting Microsoft.Web.Infrastructure.dll back in the web application bin/ directory; and now I can develop on the Mac and deploy to a Windows Server.

Use P4Merge as the Merge Tool for Mercurial Windows

Whenever I do a Mercurial merge on Windows I get a little Visual Studio Dialog popup saying File -nosplash not found. Which is annoying. Especially as I have Perforce’s excellent p4merge installed.

You can set the merge tool used by Mercurial like so:

Edit %userprofile%\Mercurial.ini

where Edit is your favourite text editor, and %userprofile% is usually C:\Users\username\.
Then add this section to your Mercurial.ini file:

p4.priority = 100 
p4.premerge = True
p4.executable = C:\Program Files\Perforce\p4merge.exe
p4.gui = True 
p4.args = $base $local $other $output

You can change “p4” to anything, so long as you change all occurrences of p4 left of the = signs.
If p4merge.exe is in your path and if you use p4merge as your identifier, then you don’t need the executable line:

p4merge.priority = 100 
p4merge.premerge = True
p4merge.gui = True 
p4merge.args = $base $local $other $output