Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono MVC5 - Views don't work

I am trying to launch MVC5 website on my Linux box using Mono and XSP4. It works with no views however when I try to render something it gives me errors.

Here is my test code. Note that I didn't change anything, this is basically a blank site without EF or any other libraries. Just bare-bone MVC5 + Razor.

public ActionResult Index()
{
    // return Content("'sall good"); // works
    return View();
}

System.InvalidOperationException

Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35

Description: HTTP 500.Error processing request.

Details: Non-web exception. Exception origin (name of application or object): System.Web.WebPages.Razor.

Stacktrace

at System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory (System.String typeName) [0x00000] in <filename unknown>:0

at System.Collections.Concurrent.ConcurrentDictionary`2+<GetOrAdd>c__AnonStorey3[System.String,System.Func`1[System.Web.WebPages.Razor.WebRazorHostFactory]].<>m__0 () [0x00000] in <filename unknown>:0 

at (wrapper delegate-invoke) System.Func`1<System.Collections.Generic.KeyValuePair`2<string, System.Func`1<System.Web.WebPages.Razor.WebRazorHostFactory>>>:invoke_TResult__this__ ()

...

I've tried to change Version=5.0.0.0 to 4.0.0.0 and 3.0.0.0 etc but nothing works. I still get the same error just now it's about 4.0.0.0.

Is there any hope?

like image 319
Stan Avatar asked Apr 21 '14 17:04

Stan


3 Answers

The problem is in Web.config that is inside /Views folder. system.web.webPages.razor host parameter must match exactly with MVC version.

For example if you have MVC 5.2.2.0 then it should look like <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />.

like image 118
Stan Avatar answered Oct 05 '22 05:10

Stan


The MVC version of your project must match the version of MvcWebRazorHostFactory, it must be the same. I had to change the version to 5.2.3.0 (in the Views/Web.config file).

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0

If you don't know which version of MVC you are using in your project, then go to Project -> Edit references -> then on the right side, under "Selected references" scroll down to System.Web.Mvc where should should see which version you are using. This is how i found out in Xamarin Studio Community.

like image 20
Tadej Avatar answered Oct 05 '22 04:10

Tadej


I received the same error after I updated my packages and ran the code.

Error: System.InvalidOperationException Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35

Change the updated version for System.Web.Mvc in Web.config file under "Views" folder

system.web.webPages.razor

host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"

I changed my version of System.Web.Mvc from 5.2.3.0 to 5.2.7.0 and the code executed.

like image 35
Krishnaveni RL Avatar answered Oct 05 '22 04:10

Krishnaveni RL