Question

I'm trying to host a ASP.NET MVC4 RC project on top of Mono 2.10.8.1. I'm getting the following exception when I access the app for the first time:

Missing method System.Web.Security.FormsAuthentication::get_IsEnabled() in assembly /usr/lib/mono/gac/System.Web/4.0.0.0__b03f5f7f11d50a3a/System.Web.dll, referenced in assembly /tmp/root-temp-aspnet-0/eaee30a1/assembly/shadow/5cf10065/40974e7d_1c664e18_00000001/System.Web.Http.WebHost.dll

According to http://www.mono-project.com/Compatibility this should be implemented in Mono 2.10.8. Microsoft lists the property as .NET Framework 4.0: http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.isenabled.aspx

Is there a work-around of some kind, or is it just not possible to host MVC4 on Mono at this time?

I should note that I'm getting this problem both when using XSP4 and mod_mono on Apache2.

Mono version is the following:

Mono JIT compiler version 2.10.8.1 (Debian 2.10.8.1-1~dhx1~lucid1)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug
        LLVM:          supported, not enabled.
        GC:            Included Boehm (with typed GC and Parallel Mark)
Was it helpful?

Solution

TL/DR: Running MVC4 under Mono is still not recommended, run MVC3 instead.

Long story: at the time Mono 2.10.x was released, Microsoft had not fully released the ASP.NET stack as open source (Razor was one of the components that was still closed source).

Recently Microsoft finally opensourced the full stack, and Mono has included it in their tree, however this has happened only in master branch (and only preview versions of Mono 2.11.x include it). Besides, the async APIs are not yet implemented in Mono (and MVC4 depends on them) so then the best bet for you is use MVC3 for now, with Mono 3.0.1 version.

Even longer story: http://tirania.org/blog/archive/2012/Mar-28.html

OTHER TIPS

It is now possible, and is almost straightforward on the current mono release and using NuGet. The fact that MS have put MVC4 stuff on NuGet helps. I've put working templates for .Net 4 & .Net 4.5 on github https://github.com/chrisfcarroll/AspNetTemplatesForMono. There are a couple of gotchas, but they're addressed in notes.

You need to compile the new XSP form the sources

git clone git://github.com/mono/xsp.git
cd xsp
./autogen.sh --prefix=/opt
make
sudo make install

This version needs enough permission to run, sudo..., otherwise you will get the System.IO.FileNotFoundException message.

Then add these lines to your web.config file

<system.web> 
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Web.Helpers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />        
        <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />        
      </assemblies>
    </compilation>

To eliminate CS0234: The type or namespace name Helpers does not exist in the namespace System.Web. exception.

Then remove these assemblies from your bin folder (if those are copied form the Windows machine)

Microsoft.Web.Infrastructure.dll
System.Net.Http.dll
System.Net.Http.Formatting.dll
System.Web.Http.dll
System.Web.Http.WebHost.dll

This will remove Missing method System.Web.Security.FormsAuthentication::get_IsEnabled() exception and many other could not load type xyz exceptions.

Please follow below link to host MVC 4 Application on Mono successfully.

http://www.bgsoftfactory.net/run-asp-net-mvc-4-with-mysql-on-linux/

It provides step by step configuration on Linux server.

Remove reference to System.Web.Http and System.Web.Http.Host if you do not need them (WebApi library). You may need to remove WebApiConfig.cs in the App_Start folder and the references in the Global.asax. But after that your project will work without any other issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top