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:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_1.0.0.0__31bf3856ad364e35\System.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:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0.0__31bf3856ad364e35\System.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的节点配置。重新编译,启动服务器,正常运行。

相关文章:

  • 2021-11-13
  • 2021-07-15
  • 2022-12-23
  • 2021-11-23
  • 2021-07-26
  • 2022-12-23
  • 2021-10-21
  • 2021-10-28
猜你喜欢
  • 2021-09-28
  • 2022-12-23
  • 2021-09-20
  • 2022-12-23
  • 2021-07-19
  • 2021-05-02
  • 2022-01-10
相关资源
相似解决方案