[A]System.Web.WebPages.Razor.Configuration.HostSection 无法转换为... web.config 问题

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to... web.config issue([A]System.Web.WebPages.Razor.Configuration.HostSection 无法转换为... web.config 问题)
本文介绍了[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,Culture=neutral, PublicKeyToken=31bf3856ad364e35' 在上下文中位置的默认"'C:WINDOWSMicrosoft.NetassemblyGAC_MSILSystem.Web.WebPages.Razorv4.0_2.0.0.0__31bf3856ad364e35System.Web.WebPages.Razor.dll'.B 型源自 'System.Web.WebPages.Razor, Version=3.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35' 在上下文中'C:UsersMyNameAppDataLocalTempTemporary 位置的默认"ASP.NETFiles oot63e7ff36a1cb775dassemblydl38f568c189b7ddacf_d04dcf01System.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:WINDOWSMicrosoft.NetassemblyGAC_MSILSystem.Web.WebPages.Razorv4.0_2.0.0.0__31bf3856ad364e35System.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:UsersMyNameAppDataLocalTempTemporary ASP.NET Files oot63e7ff36a1cb775dassemblydl38f568c189b7ddacf_d04dcf01System.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 package restore.我也更新了我的包(使用更新包),所以其中一个可能与这个问题有关.

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.

推荐答案

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

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.

更新 ViewsWeb.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 的更多信息 http://www.asp.net/mvc/tutorials/mvc-5/how-to-升级-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

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 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)