使用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, Culture = neutral,PublicKeyToken = 31bf3856ad364e35'在上下文中 '默认'在位置 ' C:\的Windows \ Microsoft.Net \组件\ GAC_MSIL \ System.Web.WebPages.Razor \ v4.0_2.0.0.0__31bf3856ad364e35 \ System.Web.WebPages.Razor.dll&#39 ;. 类型B源自' System.Web.WebPages.Razor,Version = 3.0.0.0, Culture = neutral,PublicKeyToken = 31bf3856ad364e35'在上下文中 '默认'在位置 ' C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET 文件\ VS \ 36d3424f \ d8d844c3 \组件\ 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>
答案 0 :(得分:6)
答案 1 :(得分:5)
更详细地跟进Ashish的回答
在Views文件夹中查找web.config(不是root 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软件包也没有理由重新加入。
答案 2 :(得分:0)
我遇到了这个错误,唯一修复它的是安装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,Version = 3.0.5617.31787,Culture = neutral,PublicKeyToken = 657d68e01eb7c911',位于'默认'位置'C:\ Users \ xxxxx \ Appdata \ Local \ assembly \ dl3 \ QQ3VBMNC.EO1 \ VYVECOB7 .H5J \ 2b6c89d2 \ 51158eea_9892d001 \ yyyyyy.DLL”。从'yyyyyy,Version = 3.0.5617.31787'中的'Loadyither'上下文中键入B orginates'C:\ Users \ xxxxx \ Appdata \ Local \ Microsoft \ InfoPath \ FormCache4 \ 30083E69.D18 \ cd264661b1055c58 $ b04f2786908cb791 \ yyyyyy.dll
我尝试查看注册表HKCU \ Software \ Microsoft \ Fusion \我只能看到错误消息中提到的路径,但仍然很有趣。