[A] System.Web.WebPages.Razor.Configuration.HostSection无法转换为... web.config问题 [英] [A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to... web.config issue

查看:43
本文介绍了[A] System.Web.WebPages.Razor.Configuration.HostSection无法转换为... web.config问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下错误:

无法投射[A] System.Web.WebPages.Razor.Configuration.HostSection到[B] System.Web.WebPages.Razor.Configuration.HostSection.A型源自"System.Web.WebPages.Razor,版本= 2.0.0.0,在上下文中,文化=中性,PublicKeyToken = 31bf3856ad364e35'位置为默认"'C:\ WINDOWS \ Microsoft.Net \ assembly \ GAC_MSIL \ System.Web.WebPages.Razor \ v4.0_2.0.0.0__31bf3856ad364e35 \ System.Web.WebPages.Razor.dll'.类型B源自"System.Web.WebPages.Razor,版本= 3.0.0.0,在上下文中,文化=中性,PublicKeyToken = 31bf3856ad364e35'位置'C:\ Users \ MyName \ AppData \ Local \ Temp \ Temporary的'Default'ASP.NET文件\ root \ 63e7ff36 \ a1cb775d \ assembly \ dl3 \ 8f568c18 \ 9b7ddacf_d04dcf01 \ System.Web.WebPages.Razor.dll'.

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.HostSection. Type A originates from 'System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.Web.WebPages.Razor.dll'. Type B originates from 'System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location 'C:\Users\MyName\AppData\Local\Temp\Temporary ASP.NET Files\root\63e7ff36\a1cb775d\assembly\dl3\8f568c18\9b7ddacf_d04dcf01\System.Web.WebPages.Razor.dll'.

我已经在stackoverflow上搜索了类似的问题,并且使用了他们的解决方案,但似乎并不能解决我遇到的问题.

I have searched across stackoverflow for similar issues and I used their solutions but it doesn't seem to fix the issue I am experiencing.

突然发生,我按了干净的解决方案,然后弹出此错误.我还开始在解决方案上使用nuget软件包还原.我也更新了我的软件包(使用Update-package),因此其中一个可能与此问题有关.

It suddenly occurred, I just pressed clean solution and this error popped up. I also started using nuget package restore on the solution. I updated my packages as well (using Update-package) so one of those might have something to do with this issue.

推荐答案

此错误的原因是引用了System.Web.WebPages.Razor,版本= 2.0.0.0而不是3.0.0.0的Views文件夹中的web.config.

The cause of this error is the web.config in the Views folder referencing System.Web.WebPages.Razor, Version=2.0.0.0 instead of 3.0.0.0.

通常,这可能是在nuget-package升级后发生的,这并不说明该文件夹.

Typically this can happen after a nuget-package upgrade, which does not account for this folder.

更新 Views \ Web.config 文件:

<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
  <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
  <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>

有关升级到MVC 5的更多信息,

for more information on upgrading to MVC 5 http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

这篇关于[A] System.Web.WebPages.Razor.Configuration.HostSection无法转换为... web.config问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆