本文介绍了从 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-项目到aspnet-mvc-5-and-web-api-2

我收到错误消息.有没有其他人遇到过这个错误?

I get the error. Does any one else got this error?

无法加载文件或程序集System.Web.Http,版本=4.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35' 或其中之一依赖关系.定位的程序集的清单定义没有匹配程序集引用.(来自 HRESULT 的异常:0x80131040)
描述:执行过程中发生未处理的异常当前的网络请求.请查看堆栈跟踪以了解更多信息有关错误及其在代码中的来源的信息.

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

Exception Details: System.IO.FileLoadException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

源错误:

第 48 行:第 49 行:第 50 行:} 行51:第 52 行:protected void Application_BeginRequest(object发送者,EventArgs e)

Line 48: Line 49: Line 50: } Line 51: Line 52: protected void Application_BeginRequest(object sender, EventArgs e)

源文件:d:SM7.4TestWebAPIServerV2ThirdPartyWebAPIGlobal.asax.cs 行:50

Source File: d:SM7.4TestWebAPIServerV2ThirdPartyWebAPIGlobal.asax.cs Line: 50

Assembly Load Trace:以下信息有助于确定为什么程序集 'System.Web.Http, Version=4.0.0.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35' 无法加载.

Assembly Load Trace: The following information can be helpful to determine why the assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' could not be loaded.

=== 预绑定状态信息 === LOG: DisplayName = System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35(完全指定)日志:Appbase =file:///D:/SM/7.4Test/WebAPIServerV2/ThirdPartyWebAPI/日志:初始PrivatePath = D:SM7.4TestWebAPIServerV2ThirdPartyWebAPIin调用程序集:ThirdPartyWebAPI,版本=1.0.0.0,文化=中性,公钥令牌=空.=== LOG:此绑定在默认加载上下文中启动.LOG:使用应用程序配置文件:D:SM7.4TestWebAPIServerV2ThirdPartyWebAPIweb.config 日志:使用主机配置文件:C:UsersmichalcDocumentsIISExpressconfigaspnet.config 日志:使用机器配置文件来自C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config.LOG:后政策参考:System.Web.Http,Version=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35 日志:正在尝试下载新网址file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/TemporaryASP.NET 文件/root/9184b2ea/c6d4b139/System.Web.Http.DLL.日志:正在尝试下载新 URLfile:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/TemporaryASP.NET文件/root/9184b2ea/c6d4b139/System.Web.Http/System.Web.Http.DLL.日志:正在尝试下载新 URLfile:///D:/SM/7.4Test/WebAPIServerV2/ThirdPartyWebAPI/bin/System.Web.Http.DLL.警告:比较程序集名称导致不匹配:主要版本错误:未能完成程序集的设置(hr = 0x80131040).探测终止.

=== Pre-bind state information === LOG: DisplayName = System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified) LOG: Appbase = file:///D:/SM/7.4Test/WebAPIServerV2/ThirdPartyWebAPI/ LOG: Initial PrivatePath = D:SM7.4TestWebAPIServerV2ThirdPartyWebAPIin Calling assembly : ThirdPartyWebAPI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: Using application configuration file: D:SM7.4TestWebAPIServerV2ThirdPartyWebAPIweb.config LOG: Using host configuration file: C:UsersmichalcDocumentsIISExpressconfigaspnet.config LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config. LOG: Post-policy reference: System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/9184b2ea/c6d4b139/System.Web.Http.DLL. LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/9184b2ea/c6d4b139/System.Web.Http/System.Web.Http.DLL. LOG: Attempting download of new URL file:///D:/SM/7.4Test/WebAPIServerV2/ThirdPartyWebAPI/bin/System.Web.Http.DLL. WRN: Comparing the assembly name resulted in the mismatch: Major Version ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.

堆栈跟踪:

[FileLoadException: 无法加载文件或程序集 'System.Web.Http,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35' 或它的依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(HRESULT 的例外:0x80131040)] ThirdPartyWebAPI.WebApiApplication.Application_Start()在 d:SM7.4TestWebAPIServerV2ThirdPartyWebAPIGlobal.asax.cs:50

[FileLoadException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)] ThirdPartyWebAPI.WebApiApplication.Application_Start() in d:SM7.4TestWebAPIServerV2ThirdPartyWebAPIGlobal.asax.cs:50

[HttpException (0x80004005): 无法加载文件或程序集'System.Web.Http,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35' 或其依赖项之一.这定位的程序集的清单定义与程序集不匹配参考.(来自 HRESULT 的异常:0x80131040)]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext上下文,HttpApplication 应用程序)+9935033
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtrappContext、HttpContext 上下文、MethodInfo[] 处理程序)+118
System.Web.HttpApplication.InitSpecial(HttpApplicationState 状态,MethodInfo[] 处理程序、IntPtr appContext、HttpContext 上下文)+172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtrappContext, HttpContext 上下文) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtrappContext) +296

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9935033
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): 无法加载文件或程序集'System.Web.Http,版本=4.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35' 或其依赖项之一.这定位的程序集的清单定义与程序集不匹配参考.(来自 HRESULT 的异常:0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext 上下文)+101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequestwr, HttpContext 上下文) +254

[HttpException (0x80004005): Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

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


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18408

推荐答案

我通过 解决了这个问题重新安装 NuGet 包,以纠正损坏的依赖项.在包管理器中,运行:

I fixed this by reinstalling the NuGet package, which corrects broken dependencies. From the package manager, run:

Update-Package Microsoft.AspNet.WebApi -reinstall

这篇关于从 2012 年到 2013 年更新后无法加载文件或程序集“System.Web.Http 4.0.0"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 04:26