ASP.Net MVC 4 in Xamarin Studio

Xamarin Studio is a great Mono IDE (Integrated Development Environment) in OS X area. At the time of writing this article, the version of Xamarin studio and mono framework I use are :

Xamarin Studio Version 4.2.1 (build 1) Runtime: Mono 3.2.5 ((no/964e8f0) GTK+ 2.24.20 theme: Raleigh GTK# (2.12.0.0) Package version: 302050000

Xamarin Studio includes with ASP.NET MVC 2 and 3 project template. While trying to create ASP.NET MVC 3 project, I got couples of errors such as authorization access etc. The good news is even though there is no project template for ASP.NET MVC 4, we still can convert our ASP.NET MVC 3 to run as ASP.NET MVC 4. The steps are :

  1. Create an ASP.NET MVC 3 project either with aspx or razor view engine
  2. Run the project via Xamarin studio menu (Run > Run With > Mono Soft Debugger for ASP.NET. While running the project, we may got an error message :
          System.UnauthorizedAccessException
          Access to the path "/Library/Frameworks/Mono.framework/Versions/3.2.5/etc/mono/registry" is denied.
    
          Description: HTTP 500.Error processing request.
          Details: Non-web exception. Exception origin (name of application or object): mscorlib.
          Exception stack trace:
    
          ......
    
        

    To solve the error, run the following command in terminal :
          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
        
    </code>
  3. Re-run again the ASP.NET MVC project. We may get another error message.
          System.IO.FileNotFoundException
          Could not load file or assembly 'System.Web.WebPages, Version=1.0.0.0, Culture=neutral,   PublicKeyToken=31bf3856ad364e35'  or one of its dependencies. The system cannot find the file specified.
    
          Description: HTTP 500.Error processing request.
          Details: Non-web exception. Exception origin (name of application or object): mscorlib.
          Exception stack trace:
    
           ...
        
    To solve the error message, just use NuGet package manager, search for “ASP.NET MVC 4″ and add reference to it and its dependencies.
  4. Re-run the ASP.NET MVC again. Now we may get another error message as following :
        System.InvalidOperationException
        Conflicting versions of ASP.NET Web Pages detected: specified version is "1.0.0.0", but the version in bin is "2.0.0.0".    To continue, remove files from the application's bin directory or remove the version specification in web.config.
    
        Description: HTTP 500.Error processing request.
        Details: Non-web exception. Exception origin (name of application or object): System.Web.WebPages.Deployment.
        Exception stack trace:
    
        ...
    
        
    As the error message, we need to make our ASP.NET Web Pages version to 2.0.0.0 in web.config. So just open web.config and change webpages:Version to 2.0.0.0. as follow :
        <add key="webpages:Version" value="2.0.0.0">
        </add>
        
  5. Change assembly version declared in root web.config and /View/web.config of the following


    assembly from to

    System.Web.WebPages.Razor 1.0.0.0 2.0.0.0
    System.Web.Mvc 3.0.0.0 4.0.0.0

Now re-run the project again via Xamarin Studio and our project should run well as expected.

References

  1. http://curtis.schlak.com/2013/09/29/setup-asp-net-mvc-4-on-monodevelop.html