Expression of type 'System.Web.Mvc.MvcWebRazorHostFactory' cannot be used for return type 'System.Web.WebPages.Razor.WebRazorHostFactory'

后端 未结 4 1944
庸人自扰
庸人自扰 2020-12-10 00:24

I am getting this error when I try to run a project that I took over.

I assume I have a problem in my web.config, but I don\'t know what to look for.

相关标签:
4条回答
  • 2020-12-10 00:55

    I got the same error. What worked for me: Right-click on your project and select Manage NuGet Packages. Install Microsoft ASP.NET Razor. Rebuild the project.

    0 讨论(0)
  • 2020-12-10 00:58

    Set MvcWebRazorHostFactory to version 5.0.0.0 in ALL Views/web.config Under

    <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    
    0 讨论(0)
  • 2020-12-10 01:05

    For everybody else still suffering, my solution was just like the one above, but with a tweak - I needed to match factory type version with version of System.Web.Mvc dll in your project references. To find out which version you have:

    1. Expand "References" in your project
    2. Right-click on System.Web.Mvc and look at version

    3. Update web.config in your Views folder

    So in my case it was as below:

      <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    
    0 讨论(0)
  • 2020-12-10 01:06

    Try to replace line in Web.Config

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    

    to

    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    

    (set MvcWebRazorHostFactory to version 4.0.0.0)

    0 讨论(0)
提交回复
热议问题