Does the Razor View Engine work for Mono?
Asked Answered
I

5

49

I tried searching a bit and didn't find an answer. Does the Razor View Engine work in Mono?

Insolvable answered 21/11, 2010 at 18:57 Comment(1)
Any suggestions about this?Cammi
M
60

Yes, it does. I have it working with mono on Linux.

You need mono 2.10.2+ from the stable sources from
http://ftp.novell.com/pub/mono/sources-stable/
http://download.mono-project.com/sources/mono/

Then, you need to localcopy these assemblies into your app's bin directory (you take them from Visual Studio on Windows):

System.Web.Mvc.dll
System.Web.Razor.dll
System.Web.WebPages.dll
System.Web.WebPages.Deployment.dll
System.Web.WebPages.Razor.dll

Then, you might have to get rid of the following errors you might have made like this:

Error: Storage scopes cannot be created when _AppStart is executing.
Cause: Microsoft.Web.Infrastructure.dll was localcopied to the bin directory.
Resolution: Delete Microsoft.Web.Infrastructure.dll and use the mono version.

Error: Invalid IL code in System.Web.Handlers.ScriptModule:.ctor (): method body is empty.
Cause: System.Web.Extensions.dll somehow gets localcopied to the bin directory.
Resolution: Delete System.Web.Extensions.dll and use the mono version.


Error: The classes in the module cannot be loaded. Description: HTTP 500. Error processing request.
Cause: System.Web.WebPages.Administration.dll was localcopied to the bin directory.
Resolution: Delete System.Web.WebPages.Administration.dll and unreference it


Error: Could not load type
'System.Web.WebPages.Razor.RazorBuildProvider' from assembly 'System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Description: HTTP 500. Error processing request.
Cause: System.Web.Razor.dll is corrupt or missing (or x64 instead of x32 or vice-versa) ...
Resolution: Get an uncorrupted version of System.Web.Razor.dll and localcopy to the bin directory

Edit
As of mono 2.12 / MonoDevelop 2.8, all of this is not necessary anymore.

Note that on 2.10 (Ubuntu 11.10), one needs to localcopy System.Web.DynamicData.dll as well, or else you get an error that only occurs on App_Start (if you don't do that, you get a YSOD the first time you call a page, but ONLY the first time, because only then App_Start is called.).

Note
for mono 3.0+ with ASP.NET MVC4: There is a "bug" in the install script. Or rather an incompleteness.

mod-mono, fastcgi-mono-server4 and xsp4 won't work correctly.
For example: fastcgi-mono-server4 gives you this debug output:

[error] 3384#0: *101 upstream sent unexpected FastCGI record: 3 while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "localhost:8000"

This is, because after the installation of mono3, it uses framework 4.5, but xsp, fastcgi-mono-server4 and mod-mono are not in the 4.5 GAC, only the 4.0 gac.
To fix this, use this bash script:

#!/bin/bash

# Your mono directory
#PREFIX=/usr
PREFIX=/opt/mono/3.0.3


FILES=('mod-mono-server4'
       'fastcgi-mono-server4'
       'xsp4')

cd $PREFIX/lib/mono/4.0

for file in "${FILES[@]}"
do
   cp "$file.exe" ../4.5
done


cd $PREFIX/bin

for file in "${FILES[@]}"
do
  sed -ie 's|mono/4.0|mono/4.5|g' $file
done

And if you use it via FastCGI (e.g. nginx), you also need this fix for TransmitFile for the chuncked_encoding bug
Why do I have unwanted extra bytes at the beginning of image? (fixed in mono 3.2.3)

PS:
You can get the .debs for 3.x from here:
https://www.meebey.net/posts/mono_3.0_preview_debian_ubuntu_packages/ or compile them yourselfs from github Installing Mono 3.x in Ubuntu/Debian or like this from the stable sources http://ubuntuforums.org/showthread.php?t=1591370

2015

You can now use the Xamarin provided packages

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update

If you need the vary latest features, you can also fetch the CI packages (nightly builds, so to say), if you need the latest (or almost latest) version

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://jenkins.mono-project.com/repo/debian sid main" | sudo tee /etc/apt/sources.list.d/mono-jenkins.list
sudo apt-get update
Malemute answered 21/11, 2010 at 18:57 Comment(11)
I can't find any x64 or x86 (x32 as you wrote) versions. I don't think that there is really one. Although I've got the same error for a couple of minutes, suddenly it disappeared and I can't figure out why :(Disproportion
@DotNetWise: You're right there. I couldn't find the razor assembly at first, so I took it from the MSIL GAC on x64. It didn't work then, I couldn't reference it on mono at first. And I thought it MIGHT be cause of 32/64 bit issues. It probably was corrupt due to crashes, but it's strage it works correctly on Windows then. But something is definitely fishy about System.Web.Razor.dll.Malemute
You're a champ - I'd been fighting the error with storage scopes for a while, found this and it solved it. ThanksReins
Just a quick note to say that MVC 3 has been added to Mono so it will not be necessary to jump through all the hoops above in Mono 2.12 and later.Hesper
@Justin: True as of now. Also if you use the latest version of MonoDevelop, you can keep the references made on Windows, when compiling on Linux. Plus you can also localcopy all those assemblies to the bin directory without getting an error.Malemute
I'm running Ubuntu 13.09 with the mono package from the experimental branch, but the mono-fastcgi-server4 from standard packages. This makes my mono version 3.0.6 but my fastcgi 2.10. Also running nginx. I was getting the Storage scopes cannot be created when _AppStart is executing. error until I removed the Microsoft.Web.Infrastructure.dll. So I'm curious if my fastcgi server is to blame or something else, as you said it was no longer necessary as of mono 2.12.Erdda
@Brad: Correct, Microsoft.Web.Infrastructure.dll still requires using the mono version. I've stumbled across that, too. It seems like Justin's comment isn't >>entirely<< accurate. I'm not entirely sure if it's a problem when your fasctcgi is 2.10 and not 3.0.6, i haven't run in any issues, but I tend to agree. Otherwise, you can take xsp & co. and compile them for .NET 4.5 and put these executables into that folder.Malemute
Hi. Is it legal to copy those MS libraries from Windows and/or run those libraries using Linux ?Snuffle
@Athanasios Emmanouilidis: Yes, the Apache License 2.0 allows you to copy the MVC libraries (from March 2012 version). That doesn't necessarely mean all other libraries as well, e.g. ChartControls (System.Web.UI.Visualization) require a valid Windows license.Malemute
Any suggestions for this?Cammi
@xameeramir: Using the latest mono version should resolve your issue with MVC 5. If the Xamarin package isn't current enough, use the CI packages.Malemute
E
4

Not yet.

Emend answered 21/11, 2010 at 19:5 Comment(0)
U
3

My guess is that you'll need to wait for the release of MVC3 (when it becomes open-source) before that can be answered perfectly.

I'm sure the Mono team will make it work, though.

Utham answered 21/11, 2010 at 19:0 Comment(0)
A
3

Mono 2.10 onwards fully supports MVC3 and Razor, albeit the Mono Project cannot currently ship Mono with an open-source implementation of the MVC3/Razor stack included (in the same way as MVC1 and MVC2 are included) just yet.

From the Release Notes:

Although ASP.NET MVC3 is open source and licensed under the terms of the MS-PL license, it takes a few dependencies on new libraries that are not open source nor are they part of the Microsoft.NET Framework.

At this point we do not have open source implementations of those libraries, so we can not ship the full ASP.NET MVC3 stack with Mono (We still ship ASP.NET MVC 1 and MVC 2 with Mono for your deployment enjoyment).

This Mono release however has enough bug fixes and patches that you will be able to run ASP.NET MVC3 sites with it.

Analyzer answered 7/4, 2011 at 10:20 Comment(0)
H
1

It looks like we're getting there:

http://gonzalo.name/blog/archive/2011/Jan-21.html

Looks like it isn't in any of the published versions yet, but you can run it from source control.

Homogenize answered 10/2, 2011 at 3:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.