Run a .Net Mvc5 Application on Mono

Is it possible to run ASP.NET MVC 1.0 web apps on Mono 2.4.x?

Yes, though you'll want to update the latest bugfix release for best compatibility. Note that Mono 2.4.2.3 actually includes the real ASP.NET MVC library, which was open-sourced by Microsoft under the MS-PL license.

The relationship between .NET and Mono version numbers is very complicated, as there is no direct mapping between .NET versions and features that Mono has implemented. .NET versions aren't exactly straightforward either, as 3.0 was simply additional assemblies added to the 2.0 framework, and similarly, 3.5 is additions to the 2.0SP1 framework - and the 3.5 assemblies do not depend on the 3.0 ones.

Mono features are driven by demand, using data collected using the Mono Migration Analyser.

For example, Mono has supported core .NET 2.0 features like generics since 2005 or so, but only with Mono 2.0 were the Windows Forms 2.0 and ASP.NET 2.0 components considered feature-complete - except for Web Parts, which will likely never be implemented due to low demand. And there are a couple of very Windows-specific features, like System.Management, which will also likely never be implemented as they simply cannot be mapped to non-Windows systems. Apart from such caveats, 2.0 support is now very complete.

Mono 2.0 also included full C# 3, LINQ-to-objects and LINQ-to-XML support, which are features from the .NET 3.5 framework. With Mono 2.4, the ASP.NET 3.5 features are essentially feature complete, and the only major missing 3.5 feature is LINQ-to-SQL, which should be in Mono 2.6. However, there's still no support for the .NET 3.0 assemblies - WCF, WPF, WF. WCF is being worked on but there are no plans for WPF at this time - some degree of WPF compatibility is provided via Moonlight, the Silverlight implementation.

.NET 5 and Mono

I would answer the question this way...

The .NET Framework was written by Microsoft and they have released many versions of it ( currently at 4.8 ).

There are lots of ways to think about the .NET technology stack but, for this post, .NET contains the following components:

  • A compiler suite ( C#, F#, VisualBasic .NET )
  • the Base Class Libraries ( BCL )
  • the runtime ( the bits needed to execute the compiled CIL )

The Mono project was created to implement a fully Open Source .NET Framework clone.

Initially, Mono implemented all of the above itself. For example, there is a Mono native C# compiler ( mcs ), a Mono implementation of ASP.NET, and even a Mono implementation of Windows Forms. Over time, Microsoft began releasing stuff as Open Source. Mono began incorporating this and so Microsoft .NET and Mono started to share a lot of code in common ( eg. the Roslyn C# and VB.NET compilers, ASP.NET MVC and the DLR ). Even some of the BCL code was opened up and shared between Mono and .NET. Not the runtime though.

Some of the contributors to the Mono Project formed a company, Xamarin, with the goal of using Mono to create applications for mobile operating systems like iOS and Android. They enhanced and re-used the Mono runtime ( adding a sophisticated Ahead-of-Time compiler for example ). They also re-used the Mono BCL although some parts of the BCL could not be used and new APIs were added for platform specific elements, especially GUI stuff. A "cross-platform" mobile GUI API was created as well ( called Xamarin Forms ). So while Microsoft .NET remained Windows only, Mono could be used to create applications for Mac, Linux, Windows, iOS, Android, and others.

More recently, Microsoft created their own parallel re-imagining of the .NET ecosystem. They called this new version .NET Core. Like Mono, .NET Core was Open Source and multi-platform. To differentiate the two Microsoft implementations, the original .NET was re-named to .NET Full Framework or just .NET Framework. While .NET Framework continues to be Windows only, .NET Core allows applications to run on Windows, MacOS, and Linux.

.NET Core shares a lot with .NET Full Framework. Like Mono, .NET core uses the Roslyn compiler suite for example. The BCL however was new ( partially incompatible with .NET Full Framework ). The runtime was totally new ( using RyuJIT for example ).

.NET Core did not "replace" .NET Full Framework. For example, Windows Forms and Windows Presentation Foundation ( WPF ) applications cannot be created with .NET Core.

The Mono Project ( eg. the most recent 6.12 release ) remains a clone of .NET Full Framework and, even where it has taken code from .NET Core, the goal remains .NET Framework compatibility.

So .NET found itself with multiple implementations: .NET Framework, .NET Core, Mono, and Xamarin. All of these versions were very similar but incompatible to some degree. Microsoft tried to address this by creating the idea of ".NET Standard" with the aim of specifying a shared subset of features that could be expected to execute on any of the above .NET versions.

In fact, there is kind of another branch of .NET now in that Microsoft created something called Blazor which compiles .NET applications to web assembly ( WASM ). Blazor uses the Mono / Xamarin runtime.

As another level of confusion, the .NET Core initiative produced some bits that can run on either .NET Core or .NET Full Framework. For example, ASP.NET Core is a re-imagining of ASP.NET MVC. ASP.NET Core is the only version of ASP.NET on .NET Core but both Mono and .NET Framework developers can choose from ASP.NET Web Forms, ASP.NET MVC, or ASP.NET Core. Outside of ASP.NET Core itself though, the BCL between .NET Core and .NET Framework is different and so it is quite possible to create an ASP.NET Core application that will not run on .NET Core. There is also Entity Framework Core with a similar story.

All and all, while a fantastic bucket of tech, the jumble of versions and what works with what has become a complete mess.

.NET 5 and .NET 6 (note the drop of the term "Core" in the name) are an attempt to unify and massively simplify all of the above.

By most meaningful measures, .NET 5 is a continuation of .NET Core and you could think of .NET 5 as the most recent .NET Core release. Unlike .NET Core though, it is not considered an "alternative" implementation to .NET Full Framework. Rather, it is the future for both .NET Core and .NET Full Framework. There will not be another .NET Core ( by name ) or .NET Full Framework release. Microsoft dropped "Core" from the name to signify that there is meant to be only one .NET and also skipped version 4 ( of .NET Core ) to stress that version 5 is the upgrade path for both .NET Core 3.1 and .NET Framework 4.8.

As .NET 5 is meant to replace .NET Framework, it includes things .NET Core did not like the ability to create Windows Forms and WPF applications. With .NET 5, developers will now use the same BCL for both a WPF app and a web app ( where before .NET Framework and .NET Core had different versions of the BCL ). In .NET 5, there is only one version of ASP.NET ( ASP.NET Core ).

Sadly, Microsoft was not able to finish the job of unification and, with .NET 5, you still require Xamarin ( and Mono ) to create applications for mobile operating systems like iOS and Android. This means that you still need .NET Standard as well to write code that can run on both.

The goal for .NET 6 is to bring Xamarin into the fold. To do this, .NET 6 will contain two different run-times: the one from .NET Core ( eg. RyuJIT ) and the one from Mono ( eg. MonoJIT ).

Going back to our list above, we said that .NET was a few things:

  • A compiler suite ( C#, F#, VisualBasic .NET )
  • the Base Class Libraries ( BCL )
  • the runtime ( the bits needed to execute the compiled CIL )

In .NET 6, you use the same compilers regardless of your target ( Linux, Windows, MacOS, iOS, Android, Blazor / WASM, etc ). Importantly, you also use the exact same BCL. A new cross-platform GUI API has even been envisioned to replace Xamarin Forms ( MAUI ) which will work across all targets. So, to a developer, .NET 6 looks the same no matter what you are building. This means that you do not need ".NET Standard" anymore. With .NET 6, there is only one .NET version ( that is not legacy ).

However, their are still two run-times in .NET 6: the .NET Core one and the one from Mono / Xamarin. Windows, Linux, and MacOS will use the .NET Core runtime to execute .NET Code. On iOS, Android, and WASM, .NET applications will run on the Mono run-time. Mono lives on in .NET 6 but it is only the runtime. The Mono BCL is legacy because the .NET Full Framework BCL is legacy.

So, the question "is it fair to assume that Mono will essentially become obsoleted" has two answers:

1 - Mono is not going anywhere. In fact, it is ( incredibly ) going to be part of the official .NET release from Microsoft in .NET 6 and beyond. That is, the Mono run-time is a core part of .NET 6.

2 - The full Mono Project release ( most recently version 6.12 ) is legacy as it mimics .NET Full Framework and its now legacy BCL ( eg. the old ASP.NET design -- including Web Forms ).

Microsoft has copied the Mono runtime into a different GitHub repository ( outside of the GitHub projects managed by the Mono Project ). To my knowledge, all official development is done in the Microsoft repository. As it is still Open Source however, the code can be incorporated into the Mono Project projects as well.

I have no idea what the future plans for the Mono Project are independent of the Mono runtime that is now maintained by Microsoft. As of this writing, the Mono projects at GitHub remain very active.

MVC 5 on Raspberry Pi using Mono

After a lot more googling, I have found that MVC 5 simply isn't supported by debian distributions of linux (not sure about other distributions, but I assume they aren't supported either), mainly because the current version of mono doesn't support the System.web package needed for MVC 5 projects. It will probably not become compatible in the future either, because as Chris Pratt stated MVC 6 (with ASP.NET 5) will be cross platform.

MVC 4 is nearly fully supported (as you can read here), so if you for any reason need to make a MVC project on a Raspberry Pi before ASP.NET 5 hits (or if you don't feel comfortable using an alpha version of vNext + VS2015 as described: here) then you might want to look into MVC 4.

I myself swapped to a windows server to host my MVC app.

Edit
More info about how to install mvc 4 on your Pi can be found in this question

Can XSP run ASP.NET 4.5?

You can instruct mono to launch a particular runtime version with the --runtime flag. In this case, it would be this way:

#!/bin/sh
exec /usr/bin/mono $MONO_OPTIONS --runtime=v4.5 "/usr/lib/mono/4.5/xsp4.exe" "$@"

However, as far as I understand, the 4.5 profile of .NET doesn't include changes in the runtime, but in the class libraries and compilers. So if the above doesn't work, it simply means that the version of the runtime that one needs to use to run a 4.5 application is simply the 4.0.30319 version.

The best way to understand this is to include this little image diagram grabbed from a Scott Hanselman's blog post:

Sample Image

Running Mono 3.2.0 with .NET MVC 4

Success

If you want to run MVC4 on Mono, you need to use some Microsoft dlls which are not provided by Mono at this time.

A word of caution - Taking a cursory look at the Mono source, there appears to be methods and classes in the MC4 source that do not exist in the 3.2.0 build. There may be features that are broken. The site I am running is for all intents and purposes an MVC3 site built against the latest dlls.

Microsoft DLLs to copy

  • System.Web.Abstractions - 4.0
  • System.Web.Helpers - 2.0
  • System.Web.Mvc - 4.0

Once you copy over the dlls, if you're still having problems you may have to do some detective work if the above fix doesn't work. If you get an error message saying that Mono can't find the DLL, it's usually one of three reasons:

Troubleshooting

  1. Is doesn't have the dll - You can try using the Microsoft version of the DLL

  2. It's looking for an older version of the DLL when the correct one is installed in the GAC or in your project folder - An assembly in your project is likely referencing that version somewhere. You can use a binding re-direct to force the specific version you have be used instead

  3. It stil can't find the dll - Add the assembly in the compilation/assemblies section of your web.config

  4. You're getting a 'can't find view searched...' message - if any of the views in that particular views folder have compile errors, then you'll receive this message.



Related Topics



Leave a reply



Submit