从2012年到2013年更新后无法加载文件或程序集“System.Web.Http 4.0.0”

我根据。 http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and- Web的API-2

我得到错误。 其他人是否有这个错误?

“/”应用程序中的服务器错误。

无法加载文件或程序集“System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”或其某个依赖项。 定位的程序集清单定义与程序集引用不匹配。 (来自HRESULT的exception:0x80131040)
说明:执行当前Web请求期间发生未处理的exception。 请查看堆栈跟踪,了解有关错误的更多信息以及源代码的来源。

exception详细信息:System.IO.FileLoadException:无法加载文件或程序集“System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”或其依赖项之一。 定位的程序集清单定义与程序集引用不匹配。 (来自HRESULT的exception:0x80131040)

源错误:

48行49行50行51行52行protected void Application_BeginRequest(object sender,EventArgs e)

源文件:d:\ SM \ 7.4Test \ WebAPIServerV2 \ ThirdPartyWebAPI \ Global.asax.cs行:50

程序集加载跟踪:以下信息可以帮助确定程序集“System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”无法加载的原因。

===预绑定状态信息===日志:DisplayName = System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35(完全指定)LOG:Appbase = file:/// D: /SM/7.4Test/WebAPIServerV2/ThirdPartyWebAPI/ LOG:初始PrivatePath = D:\ SM \ 7.4Test \ WebAPIServerV2 \ ThirdPartyWebAPI \ bin调用程序集:ThirdPartyWebAPI,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = null。 === LOG:这个绑定在默认的加载上下文中启动。 LOG:使用应用程序configuration文件:D:\ SM \ 7.4Test \ WebAPIServerV2 \ ThirdPartyWebAPI \ web.config LOG:使用主机configuration文件:C:\ Users \ michalc \ Documents \ IISExpress \ config \ aspnet.config LOG:使用计算机configuration文件从C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ config \ machine.config。 日志:后策略参考:System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35日志:尝试下载新的URL文件:/// C:/Windows/Microsoft.NET/Framework/v4 .0.30319 / Temporary ASP.NET Files / root / 9184b2ea / c6d4b139 / System.Web.Http.DLL。 日志:尝试下载新的URL文件:/// C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files / root / 9184b2ea / c6d4b139 / System.Web.Http / System.Web.Http .DLL。 日志:尝试下载新的URL文件:/// D:/SM/7.4Test/WebAPIServerV2/ThirdPartyWebAPI/bin/System.Web.Http.DLL。 警告:比较程序集名称导致不匹配:主版本ERR:无法完成程序集的设置(hr = 0x80131040)。 探测终止。

堆栈跟踪:

[FileLoadException:无法加载文件或程序集“System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”或其依赖项之一。 定位的程序集清单定义与程序集引用不匹配。 (来自HRESULT的exception:0x80131040)] d:\ SM \ 7.4Test \ WebAPIServerV2 \ ThirdPartyWebAPI \ Global.asax.cs中的ThirdPartyWebAPI.WebApiApplication.Application_Start():50

[HttpException(0x80004005):无法加载文件或程序集“System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”或其某个依赖项。 定位的程序集清单定义与程序集引用不匹配。 (来自HRESULT的exception:0x80131040)]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext上下文,HttpApplication应用程序)+9935033
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext,HttpContext上下文,MethodInfo []处理程序)+118
System.Web.HttpApplication.InitSpecial(HttpApplicationState状态,MethodInfo []处理程序,IntPtr appContext,HttpContext上下文)+172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext,HttpContext上下文)+336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext)+296

[HttpException(0x80004005):无法加载文件或程序集“System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35”或其某个依赖项。 定位的程序集清单定义与程序集引用不匹配。 (来自HRESULT的exception:0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext上下文)+9913572 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext上下文)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr,HttpContext上下文)+254


版本信息:Microsoft .NET Framework版本:4.0.30319; ASP.NET版本:4.0.30319.18408

我通过重新安装NuGet软件包来解决这个问题。 从包pipe理器运行:

Update-Package Microsoft.AspNet.WebApi -reinstall 

要解决无法加载文件或程序集“System.Web.Http”错误使用NuGet安装Web API 2.1 WebHost。

在参考解决scheme资源pipe理器中,右键单击并selectpipe理nuget包。 (如果没有安装nuget)

在这里输入图像描述

在左侧的“pipe理NuGet包”窗口中单击联机,然后在右上angularsearchWeb主机并安装Microsoft ASP.NET Web API 2.1 Web主机。 (一旦安装安装button将变成一个绿色的检查)

之后,项目将重新加载,当它重新生成错误将被解决,项目将debugging和运行。 错误将会消失,你可能是'找不到资源。 只需追加URL(本地主机:52088 /本地主机:52088api /产品)

你的问题很好,帮助了我。

希望这个答案有帮助!

您需要添加程序集redirect:

 <configuration> .... <runtime> <assemblyBinding> <dependentAssembly> <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="5.0.0.0" /> </dependentAssembly> </assemblyBinding> </runtime> ... </configuration> 

最有可能的是,你需要为webhosting等更多的程序集做这个工作。

或者你可以从NuGet包pipe理器控制台执行此操作

  Install-Package Microsoft.AspNet.WebApi -Version 5.0.0 

然后你将能够添加对System.Web.Http.WebHost 5.0的引用

当我安装Web Api 2.2帮助这个错误开始。 我把这个添加到web.config,它解决了我的问题。

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

我只是简单地设置Copy Local = true的缺失大会和工作。 这当然是通过右键单击缺less的引用(在错误消息中指出)并select属性来实现的。 如下:

在这里输入图像描述

这应该解决一个问题,因为可能有多个程序集导致这个问题 – 我所做的是我select了所有程序集并右键单击它们; 选定的属性; 并将它们全部设置为Copy Local = true; 然后重新发布。

是!!!

 Install-Package Microsoft.AspNet.WebApi -Version 5.0.0 

它工作正常在我的情况…. thnkz

只是一个明显的,但可能有帮助的提示….请记住检查,您的webconfig程序集绑定中指定的新版本是您在项目引用中引用相同的版本。 (即我写这个…这将是5.1.0.0,如果你最近在System.Web.Http上做了一个NUGet

  Installing NuGet package ASP.NET.MVC solved the issue for me. To install package. - Right click on project - Select "Manage NuGet Packages" - Select Online->Nuget.org from left menu - select "Microsoft ASP.NET MVC" - Click Install If you have already installed package earlier, please update the package by selecting Updates from left menu and then selecting "Microsoft ASP.NET" and click Update. 

在这里输入图像描述

在这里输入图像描述

这可能有助于某人。

我决定去与MVC4应用程序。

运行项目,工作

然后安装了几个软件包,
微软ASP.NET WEB API 2.2(4包)
Microsoft ASP.NET WEB API 2.2帮助页面
微软ASP.NET WEB API 2.2 OWIN

运行项目,问题相同的错误

解:

web.config

  <dependentAssembly> <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.2.3.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.2.3.0" /> </dependentAssembly> 

问题解决了


但是,发现了一些修复程序错误,要解决它,去你的MVC4项目的VIEW文件夹,findsecond 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> 

我find了解决scheme! 在项目目录中删除名为package的文件夹,然后重新生成运行它。

在我的情况下,我实际上完全错过了我的web.config ,它有适当的绑定redirect。 恢复web.config解决了错误。

我什么都没有,只是复制发展文件夹DLL到联机部署的Bin文件夹,它对我工作得很好。

正如其他人所说,只是使用nuget重新安装到您的Web项目的MVC包,但一定要添加MVC包到任何项目取决于Web项目,如unit testing。 如果您单独构build每个包含的项目,您将会看到巫婆需要更新。

我有同样的问题,重新安装包不起作用。

我的应用程序在LocalIIS(不是IIS EXPRESS)中运行。 我启用程序集加载跟踪,并找出它要加载从低于临时catche的System.Web.Http加载。 所以删除中的所有捕获文件夹

C:\ Windows \ Microsoft.NET \ Framework \ v4.0.30319 \ Temporary ASP.NET文件[我的应用程序]

我通过在运行nuget之后恢复nuget对web.config所做的更改来解决此问题。 恢复到以前的工作版本的变化。

  <dependentAssembly> <assemblyIdentity name="System.Web.Mvc" 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.0.0.0" newVersion="5.0.0.0" /> </dependentAssembly> <dependentAssembly> <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" /> </dependentAssembly> 

什么解决了我的问题是重新安装Microsoft ASP.NET Web API 2.2帮助页和Microsoft ASP.NET Web API 2.2 OWIN包。 我同时重新安装了两个,但是我认为是固定问题的前者。

我尝试了在这里提供的第一个解决scheme,但没有帮助,然后比较我的依赖项和工作项目(从Pluralsight的课程)和上面的两个依赖关系是一个较低的版本(5.0.0 )所以我更新到5.2.3,它开始工作。

我从一个WCF服务。 对我来说(因为问题在本地开发中显示),我只需要删除解决scheme下的bin文件夹的内容。 重build工作再次罚款。

ASP.NET版本:4.0.30319.18408属于.Net4.5和System.Web.Http版本= 4.0.0.0与.NET4.0兼容。 所以你的版本是不兼容的。 你应该更新你的System.Web.Http到版本5.0.0.0,它与.Net4.5兼容

我可以通过在主应用程序的app.config中添加程序集引用来解决与System.Net.HTTP类似的问题。

  <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-4.1.1.1" newVersion="4.0.0.0" /> </dependentAssembly></runtime> 

我有一个类似的问题。 一切都在工作之前。 它最初是使用Web Forms创build的,后来又增加了一些Web API。

  • 试图卸载,安装并重新安装Microsoft.AspNet.WebApi包。
  • 试图从解决scheme中删除包文件夹,并让NuGet恢复在VS.
  • 尝试删除个别程序集引用(在参考下)并重新安装程序包。
  • 尝试在几个答案中提到的web.config中添加绑定redirect到5.2.3.0版本。 没有为我工作。

在Visual Studio中,有效的是将发布configuration文件设置从“发布”更改为“debugging”。 奇怪,但是那是有效的。 所以在这里分享。

使用“发布”function部署到Azure时,我遇到了此问题。 记得要清除目的地的文件。

Publish Settings -> File Publish Options drop down -> Check Remove additional files at destination

这解决了我的问题,以防人们不得不像我一样寻找这个问题。 在我的项目/解决scheme中,所有内容都是相同的版本,只是不在我正在部署的目的地。