[一]System.Web.WebPages.Razor.Configuration.HostSection 不能强制转

本文关键字:不能 HostSection Configuration Razor System Web WebPages | 更新日期: 2023-09-27 18:32:49

使用 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, Version=2.0.0.0, 上下文中的区域性=中性,公钥令牌=31bf3856ad364e35' 位置的"默认" 'C:''Windows''Microsoft.Net''assembly''GAC_MSIL''System.Web.WebPages.Razor''v4.0_2.0.0.0__31bf3856ad364e35''System.Web.WebPages.Razor.dll'. B型源自'System.Web.WebPages.Razor, Version=3.0.0.0, 上下文中的区域性=中性,公钥令牌=31bf3856ad364e35' 位置的"默认" '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'.

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

[一]System.Web.WebPages.Razor.Configuration.HostSection 不能强制转

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

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命名空间内(:

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

。因为 NuGet 包也无缘无故地将其放回原处。

我遇到了这个错误,唯一修复它的方法是安装 Microsoft .NET Framework 4.5.2(离线安装程序( https://www.microsoft.com/en-us/download/details.aspx?id=42642

我之前还安装了 SQL Server 2014 客户端工具,这也可能对安装较新的 msxml 6.0 版本产生了积极影响。

我的错误信息是:

[A]xx.xxxx.ClassUserDS 不能强制转换为 [B]xx.xxxx.ClassUserDS。类型 A 源自"yyyyyy,版本=3.0.5617.31787,区域性=中性,公钥令牌=657d68e01eb7c911",位于位置"C:''Users''xxxxx''Appdata''Local''assembly''dl3''QQ3VBMNC"上下文中的"默认"。EO1''VYVECOB7.H5J''2b6c89d2''51158eea_9892d001''yyyyyy.DLL'。B 类型从"yyyy,版本=3.0.5617.31787"在上下文"LoadNboth"中生成,位于位置"C:''Users''xxxxx''Appdata''Local''Microsoft''InfoPath''FormCache4''30083E69。D18''cd264661b1055c58$b04f2786908cb791''yyyyyy.dll

我尝试在注册表编辑器中查找 hkcu''软件''Microsoft''融合'' 我只能看到错误消息中提到的路径,但很有趣。