Site stopped working in asp.net System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to

前端 未结 9 1318
盖世英雄少女心
盖世英雄少女心 2021-01-30 12:17

I have a problem like this on server

[A]System.Web.WebPages.Razor.Configuration.HostSection cannot be cast to [B]System.Web.WebPages.Razor.Configuration

相关标签:
9条回答
  • 2021-01-30 12:55

    This issue is very common when you are developing for MVC 4 and then suddently you install a package which is available in newer version so it breaks entire application.

    Only solution to such issue is to upgrade your entire application to newer or install the old package compatible with your application

    0 讨论(0)
  • 2021-01-30 12:57

    In the root Web.config make sure assemblyBinding contains the proper version for the assembly "System.Web.WebPages.Razor" and "System.Web.Mvc". Check for their actual existence as well as my "System.Web.WebPages.Razor" assembly tag was missing causing the error. I had my assembly versions set to 3.0 and 5.0 respectively in the time of this writing with full NuGet updates. Code should look something like below. The publicKeyToken will stay the same between the versions. Cheers!

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <!--some more bidings-->
      <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>
    <!--some more bidings-->
    </assemblyBinding>
    
    0 讨论(0)
  • 2021-01-30 12:58

    Ian's solution worked in one project, but for others I need the more complete info in How to Upgrade to MVC 5 and Web API 2

    0 讨论(0)
提交回复
热议问题