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

我們最近從Visual Studio Community 2013升級到Community2017。我的REST Service項目在啟動(構建過程)后開始中斷。 這僅發生在3台機器中的1台上。 我們正在使用Microsoft.AspNet.WebApi.Owin創建REST端點。

問題似乎與加載System.Web.Http有關,該庫引用到{solution_folder} /packages/Microsoft.AspNet.WebApi.Core.5.2.3/lib/net45/System.Web.Http.dll。

引用的dll位於引用的文件夾中,並且在重建時也復制到bin文件夾中。 有趣的是,當我使用VS2013重建項目時,可以從vs2013或vs2017手動啟動服務,但是當我使用vs2017重建項目並啟動它時,會出現以下錯誤:

內部異常1:FileLoadException:無法加載文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依賴項之一。 找到的程序集的清單定義與程序集引用不匹配。 (來自HRESULT的異常:0x80131040)

堆棧跟蹤:

發生System.Reflection.TargetInvocationException
HResult = 0x80131604 Message = Exception已由調用的目標引發。 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文化)
在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選項)
在Microsoft.Owin.Hosting.WebApp.Start [TStartup](字符串url)在C:\\ Projects \\ peaknx \\ PNX.OS \\ PNX.REST.Service \\ ServiceAdapter.cs中的PNX.REST.Service.ServiceAdapter.Initialize() :第32行
在C:\\ Projects \\ peaknx \\ PNX.OS \\ PNX.REST.Service \\ PNXRESTService.cs:line 85中的PNX.REST.Service.PNXRESTService.StartAdapter(對象狀態)處
在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()

內部異常1:FileLoadException:無法加載文件或程序集'System.Web.Http,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35'或其依賴項之一。 找到的程序集的清單定義與程序集引用不匹配。 (來自HRESULT的異常:0x80131040)

更新:

似乎只有在我的機器上,該構建才將app.config文件復制為ProjectName.Service.exe.config,而在其他所有文件上,它都使用Web.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>

已解決:問題是,在安裝VS2017時,必須在工作負載中檢查“ ASP.NET和Web開發”,以便VS將該項目識別為Web項目並使用Web.config而不是app.config

不幸的是,如果您錯過了此步驟,將不會有有用的錯誤報告,希望這可以幫助某人感謝您的回答。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM