Search code examples
c#asp.net-mvcrazormonomonodevelop

Can't get Razor MVC to work on Mono


I'm running through the tutorial here to build an ASP.NET MVC website: http://www.asp.net/mvc/overview/getting-started/introduction/adding-a-view. I'm not using MSVC, but MonoDevelop, as I'm on a Linux system.

I'm running into some issues when I tried to add a Razor view to My HelloWorld Controller's Index function. Right now, the code for Views/HelloWorld/Index.cshtml is this:

<h2>Index</h2>

<p>Hello from our View Template!</p>

The code for Controllers/HelloWorldController.cs's Index() function is this:

// GET: /HelloWorld/
public ActionResult Index()
{
    return View();
}

But when I go to http://127.0.0.1:8080/HelloWorld/, I'm gettng a 500 error. It's returning this information:

System.InvalidOperationException
Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.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.

Exception Stack Trace:

at System.Web.WebPages.Razor.WebRazorHostFactory.CreateFactory (System.String typeName) [0x00030] in <filename unknown>:0 
  at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (System.Collections.Concurrent.TKey key, System.Func`2 valueFactory) [0x00037] in <filename unknown>:0 
  at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfigCore (System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup config, System.String virtualPath, System.String physicalPath) [0x0004f] in <filename unknown>:0 
  at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig (System.String virtualPath, System.String physicalPath) [0x00038] in <filename unknown>:0 
  at System.Web.WebPages.Razor.WebRazorHostFactory.CreateHostFromConfig (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.GetHostFromConfig () [0x00006] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.CreateHost () [0x00000] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.get_Host () [0x00008] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.EnsureGeneratedCode () [0x00008] in <filename unknown>:0 
  at System.Web.WebPages.Razor.RazorBuildProvider.get_CodeCompilerType () [0x00000] in <filename unknown>:0 
  at System.Web.Compilation.BuildManagerDirectoryBuilder.GetBuildProviderCodeDomType (System.Web.Compilation.BuildProvider bp) [0x00000] in <filename unknown>:0 
  at System.Web.Compilation.BuildManagerDirectoryBuilder.AssignToGroup (System.Web.Compilation.BuildProvider buildProvider, System.Collections.Generic.List`1 groups) [0x0007a] in <filename unknown>:0 
  at System.Web.Compilation.BuildManagerDirectoryBuilder.Build (Boolean single) [0x00151] in <filename unknown>:0 
  at System.Web.Compilation.BuildManager.BuildInner (System.Web.VirtualPath vp, Boolean debug) [0x00019] in <filename unknown>:0 
  at System.Web.Compilation.BuildManager.Build (System.Web.VirtualPath vp) [0x00063] in <filename unknown>:0 
  at System.Web.Compilation.BuildManager.GetCompiledType (System.Web.VirtualPath virtualPath) [0x00040] in <filename unknown>:0 
  at System.Web.Compilation.BuildManager.GetCompiledType (System.String virtualPath) [0x00006] in <filename unknown>:0 
  at System.Web.Mvc.BuildManagerWrapper.System.Web.Mvc.IBuildManager.GetCompiledType (System.String virtualPath) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.BuildManagerCompiledView.Render (System.Web.Mvc.ViewContext viewContext, System.IO.TextWriter writer) [0x0001c] in <filename unknown>:0 
  at System.Web.Mvc.ViewResultBase.ExecuteResult (System.Web.Mvc.ControllerContext context) [0x00080] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult (System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x00000] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0000b] in <filename unknown>:0 
  at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive (IList`1 filters, Int32 filterIndex, System.Web.Mvc.ResultExecutingContext preContext, System.Web.Mvc.ControllerContext controllerContext, System.Web.Mvc.ActionResult actionResult) [0x0004f] in <filename unknown>:0 

Solution

  • In my Web.config file, I had to set <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc...'s version tag from 5.2.0.0 to 5.2.3.0 to match my NuGet package version.