2

I got this error after updating mvc framework to 5.2.2.0 using nuget

[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:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\vs\36d3424f\d8d844c3\assembly\dl3\a0b68557\24516c31_ea0dd001\System.Web.WebPages.Razor.dll'.

On web.config

<appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
  ...
  </appSettings>

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
              <probing privatePath="Plugins/bin/" />
              <dependentAssembly>
                <assemblyIdentity name="FluentValidation" publicKeyToken="a82054b837897c66" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.4.0.0" newVersion="3.4.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="Autofac" publicKeyToken="17863af14b0044da" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.5.0.0" newVersion="3.5.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
              </dependentAssembly>
              <dependentAssembly>
                <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
              </dependentAssembly>
            </assemblyBinding>
</runtime>
Dyrandz Famador
  • 4,303
  • 5
  • 18
  • 38
nam vo
  • 2,911
  • 11
  • 46
  • 69

3 Answers3

6

we had same issue . resolved by applying two fix : 1) there are 2 web.config file . need to change it in Root and View web.config files . 2) need to check appsettings and check below webpages tag .

Ashish
  • 77
  • 1
  • 4
6

Followup to Ashish's answer with a little more detail

Look in the Views folder for web.config (not the root web.config) and change 2.0.0.0 to 3.0.0.0 in the following:

...
<configSections>
     ...
     <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>
     ...
</configSections>
...

You may also need to remove (inside system.web.webPages.razor \ pages namespace) :

<add namespace="System.Web.Optimization"/>

...because the nuget package puts that back in for no reason too.

Scott R. Frost
  • 1,910
  • 1
  • 18
  • 23
0

I had this error, and the only thing that fixed it was installing Microsoft .NET Framework 4.5.2 (Offline Installer) https://www.microsoft.com/en-us/download/details.aspx?id=42642

I also installed SQL Server 2014 Client tools earlier, and this may also have had a positive impact by installing a newer msxml 6.0 version.

My error messsage was:

[A]xx.xxxx.ClassUserDS cannot be cast to [B]xx.xxxx.ClassUserDS. Type A originates from 'yyyyyy, Version=3.0.5617.31787, Culture=neutral, PublicKeyToken=657d68e01eb7c911' in the context 'Default' at location 'C:\Users\xxxxx\Appdata\Local\assembly\dl3\QQ3VBMNC.EO1\VYVECOB7.H5J\2b6c89d2\51158eea_9892d001\yyyyyy.DLL'. Type B orginates from 'yyyyyy, Version=3.0.5617.31787' in the context 'LoadNeither' at location 'C:\Users\xxxxx\Appdata\Local\Microsoft\InfoPath\FormCache4\30083E69.D18\cd264661b1055c58$b04f2786908cb791\yyyyyy.dll

I tried looking in regedit HKCU\Software\Microsoft\Fusion\ all I could see there was the path that is mentioned in the error message, interesting nonetheless.

hamish
  • 1,019
  • 1
  • 11
  • 19