2015-10-14 74 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(如果使用)

这似乎为我工作