Henrik Elkjær Hagen - 464 - Mar 21, 2014

I just published the RazorRockstar.WebHost project and served it with apache/mod_mono on ubuntu 13.10 running mono 3.2.5.

I got this error when trying to open the site in a browser:
System.IO.FileNotFoundException
Could not load file or assembly ‘System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35’ or one of its dependencies. The system cannot find the file specified.

How to I get rid of the error message and make the razor views work with mono?  Do I have to make changes to the web.config or maybe add System.Web.WebPages.Razor to the projects references?

Henrik Elkjær Hagen:

I manually copied the System.Web.WebPages.Razor.dll file to the folder where I published RazorRockstars. Now I do not get the error anymore and I can see the metadata page. But I get a 404 error when trying to browse to any other page.

You want to Install Microsoft.AspNet.Razor and delete the unused reference to System.Web.Entity (as Mono doesn’t support EF). I’ve also just removed this reference from the repo as well.

Henrik Elkjær Hagen:

Nothing happened when I installed Microsoft.AspNet.Razor from NuGet, I had to install Microsoft.AspNet.WebPages. Weird. Anyway I still can’t open any .cshtml pages, I just get an 404 not found. The metadata page and services works fine. Maybe it’s something wrong with my apache setup… 

Apache? can’t you just run it from xsp? i.e. hit Debug in Xamarin Studio?

Henrik Elkjær Hagen:

Yes, well we have an IT-Admin that likes apache, and we already have an apache server in place. I will try with xps.

Yeah that’s cool, but first try to see if it you have it working with xsp first, before trying to run it under a web server.

Henrik Elkjær Hagen:

I will. Thanks!

Henrik Elkjær Hagen:

Why do I want to install Microsoft.AspNet.Razor? When I install Microsoft.AspNet.Razor  from nuget in visual studio. It just switches System.Web.Razor.dll from the Servicestack one to the Microsoft.AspNet one. Then the razor pages doesn’t even show when debugging in visual studio.

Henrik Elkjær Hagen:

It works when running it from xamarin studio in windows. I’ll try to update to latest mono and xsp in ubuntu.

Sorry I meant to say install Microsoft.AspNet.WebPages which contains the config section classes in the web.config. But as I saw you already installed the correct package so it should work.
Note: It works for me on Xamarin Studio on OSX.

Henrik Elkjær Hagen:

Seems like everything is working now. All I had to do was to update mono from 3.2.5 to 3.2.8. Nice waste of 2 days.

Thanks anyway for your help Demis! 

Henrik Elkjær Hagen:

I don’t think that upgrading mono was what fixed the problem after all. I have both mono 2.10.8 and mono 3.2.8 installed. And I forgot to set some environment variables prior to running xsp. What fooled me was that these environment variables was set when I installed the new mono, and they were still set when I tried to run xsp. Thats why it worked. But when I tried again after a restart it did not work until I set the environment variables again.