我一直在开发一个MVC4解决方案,我一直在尝试将它升级到MVC5,我遵循了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文件,但没有效果...
发布于 2013-11-13 17:17:08
在您的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>发布于 2015-09-15 12:27:56
检查web.config中的版本。如果再次出现错误,请尝试清理解决方案并重新构建它。还要检查项目的Bin文件夹,从bin文件夹中移除旧的引用并重新生成项目解决方案。
发布于 2013-11-13 17:14:53
看起来你仍然有一个对Razor 2.0 dll的引用。
检查你的项目引用的属性-特别是“使用特定版本”的属性。
https://stackoverflow.com/questions/19949676
复制相似问题