我一直在研究 MVC 4 解决方案,并且一直在尝试将其升级到 MVC 5。我已按照概述的步骤进行操作 here .
我已经遵循它,现在每当我运行 MVC 应用程序时,它都会给我这个错误消息:
[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\User\AppData\Local\Temp\Temporary ASP.NET
Files\root\665ac028\de53a189\assembly\dl3\c2c0a4b5\56e8099e_40e0ce01\System.Web.WebPages.Razor.dll'.
有谁知道这是怎么来的?或者如何解决?到目前为止,我环顾四周了吗?我试过更改 web.config 文件,但无济于事...
最佳答案
在您的 Web.config
(-s) 中确保 assemblyBinding
包含程序集 System.Web.WebPages.Razor
的正确版本和 System.Web.Mvc
。
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
并确保 ConfigSections
中的 razor sectionGroup
也引用最新版本:
<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>
关于c# - Razor 2 到 Razor 3 MVC 5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19949676/