c# - DLL版本不匹配问题

标签 c# dll

* 问题简介

我正在使用一个使用 .Net 框架的软件来执行一些任务。

我们正在尝试使用 Mailkit.dll 文件,但在使用它时我们遇到了以下消息:

Internal : Could not execute code stage because exception thrown by code stage: Could not load file or assembly 'System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

从我到目前为止得出的结论来看,Mailkit.dll 依赖于 Mimekit.dll,而 Mimekit.dll 又依赖于 System.memory.dll,类似的东西。

Mailkit.dll > Mimekit.dll > System.Memory.dll

版本详细信息:

  • 机器上安装的.Net框架:4.7.3190
  • 应用程序使用的.Net框架:4.7
  • Mailkit.dll 版本:3.4.1
  • Mimekit.dll 版本:3.4.1
  • 应用程序文件夹中的System.Memory.dll版本:4.6.28619.01

我不知道问题是什么或为什么会发生这种情况,但我很确定这与版本问题有关,因此欢迎任何帮助。

最佳答案

您提供的版本号是一个很好的起点。

对于 .NETFramework 4.7,MailKit v3.4.1 依赖于 MimeKit v3.4.1,后者又依赖于 System.Memory >= v4.5.5。

NuGet 版本 v4.5.5 的 System.Memory 有 AssemblyFileVersion4.6.31308.01 (Windows 资源管理器中显示的数字)但是 AssemblyVersion4.0.1.2 。当 CLR 查找程序集时,程序集编号才是真正重要的。 CLR 寻找 v4.0.1.2加载MimeKit时却只能找到v4.0.1.1 .

最终输出的版本比所需的版本旧。我发现您输出中实际的版本来自 System.Memory v4.5.4。 AssemblyFileVersion :4.6.28619.01AssemblyVersion :4.0.1.1 .

如果您直接引用 System.Memory nuget 包,则可能会发生这种情况。如果您确实有对 System.Memory 的直接包引用,那么您需要升级它。

如果您使用 SDK 样式的项目,您会收到一个错误,阻止这种情况发生。但您仍然应该收到有关检测到的版本冲突的构建警告。 enter image description here

关于c# - DLL版本不匹配问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74602443/

相关文章:

c# - 防止某些字段被 .NET Azure Web Api 中的 PATCH 覆盖

c++ - VS2010 中的不一致链接

c# - 使用 System.Reflection 从 DLL 程序集中获取 DataMember

c# - 为图像文件或一般文件设置默认构建操作

c# - 使用 C# Interop 清除/清空办公室剪贴板

C# 锯齿状数组到列表列表

c# - 多重继承和对象 C#

windows - 在 Windows 上重命名 DLL

c++ - 在给定名称和签名的情况下调用共享库中的函数

c++ - 我在 Visual Studio 2012 Pro 中有一个 C++ DLL 类型的项目,但我无法将其编译为 CLR - 为什么会这样?