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
Several of the answers point in the right direction, but I was not sure where in the Microsoft Visual Studio for Mac interface I could find the appropriate version number to use for the version part of the factoryType
attribute.
For the benefit of other VS for Mac users, the answer is to simply right-click on the Microsoft.AspNet.Mvc
package in the Packages list in the solution explorer.
In my case, the package version was "5.2.6" after a package update, so I set the version part of the factoryType
attribute to Version=5.2.6.0
. This solved the problem.
A dialog will prompt, read carefully the package full name
field and look for the version number. For example, I have this one:
System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
So, in the Web.config (inside Views folder) replace the version number!
In my case, it originally was:
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Now I have (look at the Version value):
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
Hope it helps!
Changed the version of MvcWebRazorHostFactory to the same version of System.Web.Mvc which resolved my issue.
For MacBook users having the Visual Studio 2019, you simply go to the Web.config file and update version of the System.Web.Mvc to that which is in your Nuget packages folder.
I started getting this error in my Razor .cshtml pages in an MVC project following some NuGet package management / upgrading.
I didn't want to remove the Web.config
file completely from the Views
folder because I had customised it width some <add namespace="..." />
elements. But I noticed that the Version=... in the <host factoryType="..." />
didn't match my version of System.Web.Mvc
(checked version in Object Browser).
Altering this version number to match that of my System.Web.Mvc
assembly, and restarting Visual Studio, fixed the problem for me (as suggested by Daniel)
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.