mvc3迁移到mvc4后,发布到服务器,出现了如下错误:
[A]System.Web.WebPages.Razor.Configuration.RazorPagesSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration.RazorPagesSection. Type A From"System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"(In the context of"Default"In the"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.WebPages.Razorv4.0_1.0.0.0__31bf3856ad364e35System.Web.WebPages.Razor.dll"Position). Type B From"System.Web.WebPages.Razor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"(In the context of"Default"In the"C:WindowsMicrosoft.NetassemblyGAC_MSILSystem.Web.WebPages.Razorv4.0_2.0.0.0__31bf3856ad364e35System.Web.WebPages.Razor.dll"Position).
看原因,可能是GAC程序集和当前程序集冲突的缘故,遂修改节点如下,添加了Syste.Web.WebPages.Razor的节点:
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0"/> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" /> <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="1.0.0.0" /> </dependentAssembly> </assemblyBinding>
之后,注释掉web.config中所有的关于ext.net的节点配置。重新编译,启动服务器,正常运行。