简体   繁体   English

从vs2013升级到vs2017后无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0'

[英]Could not load file or assembly 'System.Web.Http, Version=4.0.0.0' after upgrading from vs2013 to vs2017

we recently upgraded from Visual Studio Community 2013 to Community 2017. My REST Service project started breaking after starting it (build passes). 我们最近从Visual Studio Community 2013升级到Community2017。我的REST Service项目在启动(构建过程)后开始中断。 This is only happening on one out of 3 machines. 这仅发生在3台机器中的1台上。 We are using Microsoft.AspNet.WebApi.Owin for creating our REST endpoints. 我们正在使用Microsoft.AspNet.WebApi.Owin创建REST端点。

The issue seems to be on loading System.Web.Http, the library is referenced to {solution_folder}/packages/Microsoft.AspNet.WebApi.Core.5.2.3/lib/net45/System.Web.Http.dll. 问题似乎与加载System.Web.Http有关,该库引用到{solution_folder} /packages/Microsoft.AspNet.WebApi.Core.5.2.3/lib/net45/System.Web.Http.dll。

The referenced dll is in referenced folder and also copies to bin folder when rebuilding. 引用的dll位于引用的文件夹中,并且在重建时也复制到bin文件夹中。 Interesting thing is that when I rebuild the project with VS2013 I can start the service manually, from vs2013 or vs2017, but when I rebuild the project with vs2017 and start it I get the following error: 有趣的是,当我使用VS2013重建项目时,可以从vs2013或vs2017手动启动服务,但是当我使用vs2017重建项目并启动它时,会出现以下错误:

Inner Exception 1: FileLoadException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 内部异常1:FileLoadException:无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference. 找到的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (来自HRESULT的异常:0x80131040)

Stacktrace: 堆栈跟踪:

System.Reflection.TargetInvocationException occurred 发生System.Reflection.TargetInvocationException
HResult=0x80131604 Message=Exception has been thrown by the target of an invocation. HResult = 0x80131604 Message = Exception已由调用的目标引发。 Source=mscorlib StackTrace: at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) Source = mscorlib StackTrace:在System.RuntimeMethodHandle.InvokeMethod(对象目标,Object []参数,签名sig,布尔值构造函数)在System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj,Object []参数,Object []参数)在System .Reflection.RuntimeMethodInfo.Invoke(Object obj,BindingFlags invokeAttr,Binder活页夹,Object []参数,CultureInfo文化)
at Owin.Loader.DefaultLoader.<>c__DisplayClass12.b__b(IAppBuilder builder) at Owin.Loader.DefaultLoader.<>c__DisplayClass1.b__0(IAppBuilder builder) at Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(StartContext context) at Microsoft.Owin.Hosting.Engine.HostingEngine.Start(StartContext context) at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options) at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options) at Microsoft.Owin.Hosting.WebApp.StartImplementation(IServiceProvider services, StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start(StartOptions options) at Microsoft.Owin.Hosting.WebApp.Start[TStartup](StartOptions options) 在Owin.Loader.DefaultLoader。<> c__DisplayClass12.b__b(IAppBuilder构建器)处,在Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(StartContext上下文)在Microsoft.Owin.Hosting.Engine.HostingEngine.ResolveApp(StartContext上下文)在Owin.Loader.DefaultLoader。<> c__DisplayClass1.b__0(IAppBuilder构建器) Microsoft.Owin.Hosting.Starting.HostingStarter.Start(StartOptions选项)的Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions选项)的.Owin.Hosting.Engine.HostingEngine.Start(StartContext上下文) .Hosting.WebApp.StartImplementation(IServiceProvider服务,StartOptions选项),位于Microsoft.Owin.Hosting.WebApp.Start(StartOptions选项),位于Microsoft.Owin.Hosting.WebApp.Start [TStartup](StartOptions选项)
at Microsoft.Owin.Hosting.WebApp.Start[TStartup](String url) at PNX.REST.Service.ServiceAdapter.Initialize() in C:\\Projects\\peaknx\\PNX.OS\\PNX.REST.Service\\ServiceAdapter.cs:line 32 在Microsoft.Owin.Hosting.WebApp.Start [TStartup](字符串url)在C:\\ Projects \\ peaknx \\ PNX.OS \\ PNX.REST.Service \\ ServiceAdapter.cs中的PNX.REST.Service.ServiceAdapter.Initialize() :第32行
at PNX.REST.Service.PNXRESTService.StartAdapter(Object state) in C:\\Projects\\peaknx\\PNX.OS\\PNX.REST.Service\\PNXRESTService.cs:line 85 在C:\\ Projects \\ peaknx \\ PNX.OS \\ PNX.REST.Service \\ PNXRESTService.cs:line 85中的PNX.REST.Service.PNXRESTService.StartAdapter(对象状态)处
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx) at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 在System.Threading.ExecutionContext.RunInternal(ExecutionContext执行上下文,ContextCallback回调,对象状态,布尔值保持SyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContext执行上下文,ContextCallback回调,对象状态)处的System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(对象状态)处,位于System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()位于System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()

Inner Exception 1: FileLoadException: Could not load file or assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 内部异常1:FileLoadException:无法加载文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依赖项之一。 The located assembly's manifest definition does not match the assembly reference. 找到的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040) (来自HRESULT的异常:0x80131040)

Update: 更新:

It seems that only on my machine the build copies app.config file as ProjectName.Service.exe.config, where as on all others it uses Web.config. 似乎只有在我的机器上,该构建才将app.config文件复制为ProjectName.Service.exe.config,而在其他所有文件上,它都使用Web.config。

Basically I never get my dependency redirection going and it always looks for System.Web.Http 4.0.0.0 instead of 5.2.3.0 since this part of configuration is not in ProjectName.Service.exe.config. 基本上,我从来没有实现过依赖关系重定向,它总是寻找System.Web.Http 4.0.0.0而不是5.2.3.0,因为这部分配置不在ProjectName.Service.exe.config中。

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

SOLVED: The problem was that when installing VS2017 you must check "ASP.NET and web development" in workloads in order for VS to recognize the project as Web project and use Web.config instead of app.config 已解决:问题是,在安装VS2017时,必须在工作负载中检查“ ASP.NET和Web开发”,以便VS将该项目识别为Web项目并使用Web.config而不是app.config

Unfortunately if you miss this step there will be no useful error report, hope this helps someone thanks for the answers. 不幸的是,如果您错过了此步骤,将不会有有用的错误报告,希望这可以帮助某人感谢您的回答。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 System.Web.Http 加载文件或程序集,版本 = 4.0.0.0 - Cannot load file or assembly with System.Web.Http, Version=4.0.0.0 从 2012 年到 2013 年更新后无法加载文件或程序集“System.Web.Http 4.0.0” - Could not load file or assembly 'System.Web.Http 4.0.0 after update from 2012 to 2013 无法加载文件或程序集&#39;System.Web.Http,Version = 5.2.2.0 - Could not load file or assembly 'System.Web.Http, Version=5.2.2.0 天蓝色错误部署无法解析此参考。 无法找到程序集System.Web.Http,版本= 4.0.0.0 - Deploying in azure error Could not resolve this reference. Could not locate the assembly System.Web.Http, Version=4.0.0.0 .net core 3.0 无法加载文件或程序集“System.Web.Http 版本=5.2.7.0” - .net core 3.0 Could not load file or assembly 'System.Web.Http Version=5.2.7.0' 无法加载文件或程序集 'System.Web.Services,版本 = 4.0.0.0 - Could not load file or assembly 'System.Web.Services, Version=4.0.0.0 无法加载文件或程序集&#39;System.ServiceModel.Web,版本= 4.0.0.0&#39; - Could not load file or assembly 'System.ServiceModel.Web, Version=4.0.0.0' 无法加载文件或程序集“ System.Web.MVC,版本4.0.0.0” - could not load file or assembly 'System.Web.MVC, version 4.0.0.0,' 从VS2015迁移到VS2017后,无法加载程序集WindowsBase - Could not load assembly WindowsBase after project migration from VS2015 to VS2017 无法加载文件或程序集&#39;System.Web.Http.WebHost,版本= 4.0.0.0,区域性=中性,PublicKeyToken - Could not load file or assembly 'System.Web.Http.WebHost, Version=4.0.0.0, Culture=neutral, PublicKeyToken
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM