2015-10-14 75 views
0

我似乎無法加載VS2010 ConsoleApplication中的System.Net.Http.Formatting.dll,即使我設置了重定向。這裏的錯誤DLL重定向 - 內部版本號不匹配

System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. 
File name: 'System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 
    at uk.ac.salford.accman.backend.service.Models.WebService.AlmaRestClient.CreateOrUpdateUser(Operator user, Account account, JanusUser janusUser) 
    at Salford.AccMan.BackEnd.Processes.Janus.UpdateALMAUser.ProcessTransaction(Transaction& transaction) in C:\VS2010\Accman.NET\AccManBackEndLibrary\Processes\Janus\UpdateALMAUser.cs:line 121 
    at Salford.AccMan.BackEnd.Processes.TransactionServiceProcess.Process() in C:\VS2010\Accman.NET\AccManBackEndLibrary\TransactionServiceProcess.cs:line 147 

=== Pre-bind state information === 
LOG: DisplayName = System.Net.Http.Formatting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 
(Fully-specified) 
LOG: Appbase = file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/ 
LOG: Initial PrivatePath = NULL 
Calling assembly : AccManLibrary, Version=3.0.4.0, Culture=neutral, PublicKeyToken=null. 
=== 
LOG: This bind starts in LoadFrom load context. 
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load(). 
LOG: Using application configuration file: C:\VS2010\.NET Code Library\ConsoleSchedulerService\ConsoleSchedulerService\bin\Debug\ConsoleSchedulerService.exe.Config 
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. 
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.0.21112.0. 
LOG: Post-policy reference: System.Net.Http.Formatting, Version=4.0.21112.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 
LOG: Attempting download of new URL file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/System.Net.Http.Formatting.DLL. 
LOG: Attempting download of new URL file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL. 
LOG: Attempting download of new URL file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/redirect/System.Net.Http.Formatting.DLL. 
LOG: Attempting download of new URL file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/redirect/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL. 
LOG: Attempting download of new URL file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/System.Net.Http.Formatting.EXE. 
LOG: Attempting download of new URL file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/System.Net.Http.Formatting/System.Net.Http.Formatting.EXE. 
LOG: Attempting download of new URL file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/redirect/System.Net.Http.Formatting.EXE. 
LOG: Attempting download of new URL file:///C:/VS2010/.NET Code Library/ConsoleSchedulerService/ConsoleSchedulerService/bin/Debug/redirect/System.Net.Http.Formatting/System.Net.Http.Formatting.EXE. 
LOG: Attempting download of new URL file:///C:/VS2010/Accman.NET/AccManBackEndLibrary/bin/System.Net.Http.Formatting.DLL. 
WRN: Comparing the assembly name resulted in the mismatch: Build Number 
LOG: Attempting download of new URL file:///C:/VS2010/Accman.NET/AccManBackEndLibrary/bin/System.Net.Http.Formatting/System.Net.Http.Formatting.DLL. 
LOG: Attempting download of new URL file:///C:/VS2010/Accman.NET/AccManBackEndLibrary/bin/System.Net.Http.Formatting.EXE. 
LOG: Attempting download of new URL file:///C:/VS2010/Accman.NET/AccManBackEndLibrary/bin/System.Net.Http.Formatting/System.Net.Http.Formatting.EXE. 

所以,我的理解是,它在尋找System.Net.Http.Formatting,版本= 4.0.0.0,但我的項目中包含的版本4.0.21112.0,所以我成立了一個重定向(這也是在堆棧跟蹤中提到,所以我知道重定向至少被拾起)

我重定向是:

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

它發現在C較新的DLL:/VS2010/Accman.NET/ AccManBackEndLibrary/bin,但抱怨內部版本號不正確。不過,據我所知,整個版本號是正確的。

如果我運行PowerShell命令得到它返回相同數量的確切版本號:

PS F:\> (get-item C:\VS2010\Accman.NET\AccManBackEndLibrary\bin\System.Net.Http.Formatting.dll).VersionInfo 

ProductVersion FileVersion  FileName 
-------------- -----------  -------- 
4.0.21112.0  4.0.21112.0  C:\VS2010\Accman.NET\AccManBackEndLibrary\bin\System.Net.Http.Formatting.dll 

請幫幫忙!我究竟做錯了什麼?

感謝

回答

1

你可以從項目中刪除DLL的參考和手動重新添加你的DLL。
(解決方案資源管理器 - >參考 - >添加 - >瀏覽)
應該解決問題。

+0

謝謝,你的意思刪除Visual Studio中的項目引用? – Richard

+0

是的,在看到您的評論之前正在進行編輯:) – user5226582

+0

對不起,延遲迴復。這似乎並沒有解決不幸的問題,但我將刪除所有內容,並且在嘗試重新添加它們(手動)之前仔細檢查是否沒有任何延遲的引用,而不是使用Nuget並查看是否可以讓它工作。謝謝 – Richard

0

回答1

吧,如果你想使用隨.NET 4捆綁System.Net.Http.Formatting,System.Net.Http和System.Net.WebRequest版本的第一個答案,這是我的(遺留)項目使用的。

  • 刪除對這些包的每一個引用(包括packages.config和Nuget包管理器)。另外如果你的問題出現了,因爲你像我一樣從Nuget安裝了NewtonSoft.Json,那麼也刪除它。

  • 手動將其添加爲@ user5226582建議(右鍵單擊引用在項目 - >添加引用 - >組件 - >擴展注意我選擇了他們從捆綁的擴展組件

  • 而且,。如果你正在使用它的NewtonSoft.Json.dll做同樣這也是在組件 - >擴展

  • 從app.config中

0123刪除與這些文件的任何bindingRedirects

現在這是一個公平的競爭環境,因爲所有的DLL都來自同一個地方,並且應該相互兼容。

答案2

System.Net.Http已取代Microsoft.Net.Http。刪除任何現有的引用和相關的綁定重定向(如答案1)。

  • 使用的NuGet安裝Microsoft.Net.Http
  • 使用的NuGet安裝NewtonSoft.Json(如果使用)

這似乎爲我工作