首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >DLL重定向-内部版本号不匹配

DLL重定向-内部版本号不匹配
EN

Stack Overflow用户
提问于 2015-10-14 23:07:50
回答 3查看 4.4K关注 0票数 4

即使我设置了重定向,在VS2010 ConsoleApplication中加载System.Net.Http.Formatting.dll似乎也有问题。错误是这样的

代码语言:javascript
复制
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、Version=4.0.0.0,但我的项目包含版本4.0.21112.0,所以我设置了一个重定向(堆栈跟踪中也提到了这个重定向,所以我知道这个重定向至少被提取出来了)

我的重定向是:

代码语言:javascript
复制
      <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,中找到较新的动态链接库,但报告内部版本号不正确。但是,据我所知,整个版本号都是正确的。

如果我运行Powershell命令来获取确切的版本号,它将返回相同的版本号:

代码语言:javascript
复制
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

请帮帮我!我做错了什么?

谢谢

EN

Stack Overflow用户

发布于 2015-10-15 22:01:15

答案1

如果你想使用与.NET 4捆绑在一起的System.Net.Http.Formatting、System.Net.Http和System.Net.WebRequest版本,第一个答案就是我的(遗留)项目使用的版本。

  • 删除对这些包的每个引用(包括packages.config和Nuget包管理器)。另外,如果你的问题是因为你像我一样从Nuget安装了NewtonSoft.Json,那就把它也删除掉。
  • 按照@user5226582的建议手动添加它们(右键单击项目中的引用-> add Reference -> Assemblies -> Extensions。请注意,我是从捆绑的扩展Assemblies.
  • Also,中选择的,如果您正在使用NewtonSoft.Json.dll,请对它执行相同的操作。这也位于app.config

中与这些文件相关的Assemblies Extensions.

  • Remove any bindingRedirects中

现在它是一个公平的竞争环境,因为所有的DLL都来自同一个地方,并且应该彼此兼容。

Answer 2

Microsoft.Net.Http已经取代了System.Net.Http。删除任何现有的引用和相关的bindingRedirects (如答案1所示)。

  • 使用Nuget安装Microsoft.Net.Http
  • 使用Nuget安装NewtonSoft.Json (如果使用)

这似乎对我很管用

票数 2
EN
查看全部 3 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33129050

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档