Razor Host Factory error
I get a MvcWebRazorHostFactory error trying to run my app, but it's not an MVC app at all. I have the following web packages installed via nuget:
Microsoft ASP.NET Razor
Microsoft ASP.NET Web API 2.1
Microsoft ASP.NET Web Pages
My app is angularjs front end using razor views (.cshtml). I don't understand why I keep getting this error.
An exception of type 'System.InvalidOperationException' occurred in System.Web.WebPages.Razor.dll but was not handled in user code
Additional information: Could not locate Razor Host Factory type: System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35
And here is the razor section in my web.config:
<system.web.webPages.razor>
<host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.WebPages.WebPage">
<namespaces>
<add namespace="System.Web.Configuration" />
<add namespace="System.Web.Optimization" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
I resolved this issue by setting System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc
Version to 5.2.0.0 and it worked, finally! Why 5.2.0.0? Same version as NuGet Microsoft ASP.NET project. So, the line in /Views/Web.Config looks:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
For the benefit of anyone developing ASP.NET MVC 5 web apps using Xamarin Studio v5.5.3 on OSX, deleting the /Views/Web.config did not work for me and created other errors.
To fix it, open /Views/Web.config and change all instances of 5.2.0.0 to 5.2. 2 .0
More details here
So apparently some package I got from nuget adds a web.config to the Views folder. In this web.config there were settings for the MvcWebRazorHostFactory. I think this occurred when I added a View to my project using the dialog box.
The solution is to remove the web.config from the Views folder.
链接地址: http://www.djcxy.com/p/64290.html上一篇: 如何解决? 假设程序集引用'System.Web.Mvc
下一篇: Razor Host Factory错误