C# [A] System.Web.WebPages.Razor.Configuration.HostSection无法强制转换为[B]System.Web.WebPages.Razor.Configuration.HostSection

C# [A] System.Web.WebPages.Razor.Configuration.HostSection无法强制转换为[B]System.Web.WebPages.Razor.Configuration.HostSection,c#,asp.net,asp.net-mvc,C#,Asp.net,Asp.net Mvc,在使用nuget将mvc框架更新为5.2.2.0之后,我遇到了这个错误 [A] 无法强制转换System.Web.WebPages.Razor.Configuration.HostSection 至[B]System.Web.WebPages.Razor.Configuration.HostSection。A型 源自“System.Web.WebPages.Razor,版本=2.0.0.0”, 区域性=中性,PublicKeyToken=31bf3856ad364e35'在上下文中 位置处的“默

在使用nuget将mvc框架更新为5.2.2.0之后,我遇到了这个错误

[A] 无法强制转换System.Web.WebPages.Razor.Configuration.HostSection 至[B]System.Web.WebPages.Razor.Configuration.HostSection。A型 源自“System.Web.WebPages.Razor,版本=2.0.0.0”, 区域性=中性,PublicKeyToken=31bf3856ad364e35'在上下文中 位置处的“默认值” 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.WebPages.Razor\v4.0_2.0.0_uuu31BF3856AD364E35\System.Web.WebPages.Razor.dll'。 类型B源于'System.Web.WebPages.Razor,版本=3.0.0.0, 区域性=中性,PublicKeyToken=31bf3856ad364e35'在上下文中 位置处的“默认值” 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET 文件\vs\36d3424f\d8d844c3\assembly\dl3\a0b68557\24516c31\u ea0dd001\System.Web.WebPages.Razor.dll'

在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>

...
我们遇到了同样的问题。 通过应用两个修复程序解决: 1) 有2个web.config文件。需要在根目录中更改它并查看web.config文件。 2) 需要检查appsettings并检查以下网页标签。

接下来是Ashish的回答,再详细一点

在“视图”文件夹中查找web.config(而不是根web.config),并在以下内容中将2.0.0.0更改为3.0.0.0

...
<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>
...
。。。
...
...
...
...
您可能还需要删除(在system.web.webPages.razor\pages命名空间内):



…因为nuget软件包也无缘无故地把它放了回去。

我遇到了这个错误,唯一修复它的是安装Microsoft.NET Framework 4.5.2(脱机安装程序)

我也在早些时候安装了SQL Server 2014客户端工具,通过安装更新的msxml 6.0版本,这也可能产生了积极的影响

我的错误是:

[A] xx.xxxx.ClassUserDS不能强制转换为[B]xx.xxxx.ClassUserDS。类型A源于“C:\Users\xxxxx\Appdata\Local\assembly\dl3\QQ3VBMNC.EO1\VYVECOB7.H5J\2b6c89d2\51158eea\U 9892d001\YYYYY.DLL”位置的上下文“Default”中的“YYYYY,版本=3.0.5617.31787,区域性=中性,PublicKeyToken=657d68e01eb7c911”。类型B源于“C:\Users\xxxxx\Appdata\Local\Microsoft\InfoPath\FormCache4\30083E69.D18\cd264661b1055c58$b04f2786908cb791\yyyyyyy.dll”上下文“LoadNone”中的“yyyyyy,Version=3.0.5617.31787”


我试着在regedit HKCU\Software\Microsoft\Fusion\中查找,我所能看到的只是错误消息中提到的路径,尽管如此,还是很有趣。

您可能查看了错误的web.config。在您的视图文件夹中还有一个web.config,这很可能是错误的来源。谢谢,我已经修复了它。
<add namespace="System.Web.Optimization"/>