c# – DLL重定向 – 内部版本号不匹配

我似乎无法在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

请帮忙!我究竟做错了什么?

谢谢

最佳答案 您可以从项目中删除dll引用并手动重新添加您拥有的DLL.

(Solution Explorer – > References – > Add – > Browse)

应该解决问题.

点赞