This question already has answers here:
[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to… web.config issue
(6个答案)
3个月前关闭。
使用nuget将mvc框架更新为5.2.2.0后出现此错误
[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:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \临时ASP.NET
文件\ vs \ 36d3424f \ d8d844c3 \ assembly \ dl3 \ a0b68557 \ 24516c31_ea0dd001 \ System.Web.WebPages.Razor.dll'。
在web.config上
(6个答案)
3个月前关闭。
使用nuget将mvc框架更新为5.2.2.0后出现此错误
[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:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \临时ASP.NET
文件\ vs \ 36d3424f \ d8d844c3 \ assembly \ dl3 \ a0b68557 \ 24516c31_ea0dd001 \ System.Web.WebPages.Razor.dll'。
在web.config上
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
...
</appSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="Plugins/bin/" />
<dependentAssembly>
<assemblyIdentity name="FluentValidation" publicKeyToken="a82054b837897c66" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.4.0.0" newVersion="3.4.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
最佳答案
我们有同样的问题。
通过应用两个修复程序来解决:
1)有2个web.config文件。需要在Root和View web.config文件中进行更改。
2)需要检查appsettings并检查下面的webpages标签。
关于c# - 无法将[A] System.Web.WebPages.Razor.Configuration.HostSection强制转换为[B] System.Web.WebPages.Razor.Configuration.HostSection ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27242339/
10-10 18:49