asp.net-mvc “System.Web.Mvc.MvcWebRazorHostFactory”类型的表达式不能用于返回类型“System.Web.WebPages.Razor.WebRazorHostFactory”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15617625/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:41:22  来源:igfitidea点击:

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

asp.net-mvcasp.net-mvc-3asp.net-mvc-4razor

提问by Dave

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.

我假设我的web.config有问题,但我不知道要查找什么。

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

“System.Web.Mvc.MvcWebRazorHostFactory”类型的表达式不能用于返回类型“System.Web.WebPages.Razor.WebRazorHostFactory”

Any suggestions on the same are highly appreciated.

任何关于相同的建议都受到高度赞赏。

回答by menkow

Try to replace line in Web.Config

尝试替换 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)

(将 MvcWebRazorHostFactory 设置为 4.0.0.0 版)

回答by user2009677

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

在 ALL Views/web.config 下将 MvcWebRazorHostFactory 设置为 version 5.0.0.0

<system.web.webPages.razor>
    <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

回答by ukie

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:

对于仍然遭受痛苦的其他人,我的解决方案就像上面的解决方案一样,但进行了调整- 我需要将工厂类型版本与项目引用中的 System.Web.Mvc dll 版本相匹配。要了解您使用的是哪个版本:

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

    enter image description here

  3. Update web.config in your Views folder

  1. 在您的项目中展开“参考”
  2. 右键单击 System.Web.Mvc 并查看版本

    在此处输入图片说明

  3. 更新Views 文件夹中的web.config

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" />

回答by mvuong

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.

我得到了同样的错误。对我有用的方法:右键单击您的项目并选择管理 NuGet 包。安装 Microsoft ASP.NET Razor。重建项目。