我似乎无法在VS2010 ConsoleApplication中加载System.Net.Http.Formatting.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:/VS2010/Accman.NET/AccManBackEndLibrary/bin中找到了较新的DLL,但是抱怨构建号不正确。但是,据我所知,整个版本号是正确的。
如果我运行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
请帮忙!我做错了什么?
由于
答案 0 :(得分:2)
您可以从项目中删除dll参考,然后手动重新添加您拥有的dll
(Solution Explorer - &gt; References - &gt; Add - &gt; Browse)
应该解决问题。
答案 1 :(得分:0)
回答1
是的,首先回答是否要使用与.NET 4捆绑在一起的System.Net.Http.Formatting,System.Net.Http和System.Net.WebRequest版本,这就是我的(遗留)项目使用。
删除对这些包的每一个引用(包括packages.config和Nuget包管理器)。此外,如果您的问题是因为您像我一样从Nuget安装了NewtonSoft.Json,那么也要删除它。
手动将它们添加为@ user5226582建议(右键单击项目中的引用 - &gt;添加引用 - &gt; 程序集 - &gt;扩展。请注意我从捆绑的扩展中选择它们组件。
此外,如果您正在使用它,请对NewtonSoft.Json.dll执行相同的操作。那也是在Assemblies中 - &gt;扩展
从app.config
现在它是一个公平竞争的领域,因为所有的DLL都来自同一个地方,并且应该彼此兼容。
回答2
System.Net.Http已被Microsoft.Net.Http取代。删除任何现有的引用和相关的bindingRedirects(如答案1中所示)。
这似乎对我有用
答案 2 :(得分:0)
包文件版本和汇编版本不一定一致: