2

* Introduction to the Issue

I am using a software that uses the .Net framework to perform some tasks.

We are trying to use the Mailkit.dll file but when using it we are faced with the message:

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)

and from what I have concluded so far the Mailkit.dll depends on Mimekit.dll that depends on System.memory.dll, something like that.

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

Version details:

  • .Net framework installed on machine: 4.7.3190
  • .Net framework used by application: 4.7
  • Mailkit.dll version: 3.4.1
  • Mimekit.dll Version: 3.4.1
  • System.Memory.dll in application folder Version:4.6.28619.01

I don't Know what's the issue or why this is happening but I am pretty sure it has to do with version issue so any help is welcomed.

yousif fayed
  • 331
  • 1
  • 4
  • 20
  • it seems you have a newer version in your system, that means your compiled version is newer than the required one, you can copy the dll to the required location and check if that helps – DonMiguelSanchez Nov 28 '22 at 15:07
  • 2
    https://stackoverflow.com/questions/43365736/assembly-binding-redirect-how-and-why – Hans Passant Nov 28 '22 at 15:18
  • VS upgrade process must of failed which often happens. The version of the Net libraries installed on machine do not match the version in csproj file. Easiest way of fixing is to use VS and in the Solution Explorer delete the references that are giving errors. The from VS menu Project : Add Reference on Net tab and add references that are missing. This will update the version numbers in the csproj file to match the installed version of the libraries. Make backup copies of everything before proceeding. This should be automatic but upgrade process doesn't find a library and then crashes. – jdweng Nov 28 '22 at 15:36
  • +1 for including all the details required to find the cause of the problem in the text of the question (exact error message, preliminary analysis, version details). – Heinzi Nov 28 '22 at 17:13
  • @DonMiguelSanchez yes this is the issue – yousif fayed Nov 29 '22 at 08:07
  • @HansPassant this will be my last resort if i can't find a solution – yousif fayed Nov 29 '22 at 08:07
  • @jdweng I don't think the Update failed but i do think that its a version issue – yousif fayed Nov 29 '22 at 08:07
  • @Heinzi Thank you, I tried to just state all the needed info – yousif fayed Nov 29 '22 at 08:07
  • If the update was successful you wouldn't be getting the error. – jdweng Nov 29 '22 at 09:40

1 Answers1

4

The version numbers you provided are a good starting point.

For .NETFramework 4.7, MailKit v3.4.1 depends on MimeKit v3.4.1 which depends on System.Memory >= v4.5.5.

System.Memory with NuGet version v4.5.5 has an AssemblyFileVersion of 4.6.31308.01 (the number that shows in windows explorer) but an AssemblyVersion of 4.0.1.2. The assembly number is what really matters when the CLR looks for assemblies. The CLR looks for v4.0.1.2 when loading MimeKit but can only find v4.0.1.1.

The version that ends up in your output is older than the version required. I found that the version that is actually in your output is from System.Memory v4.5.4. AssemblyFileVersion: 4.6.28619.01. AssemblyVersion: 4.0.1.1.

This is probably happening if you are referencing System.Memory nuget package directly. If you do have a direct package reference to System.Memory, then you need to upgrade it.

If you were using SDK styled projects, you would get an error preventing this from happening. But you should still be getting a build warning about version conflicts detected. enter image description here

Hank
  • 1,976
  • 10
  • 15
  • First of all thank you for your time. The issue is that when trying to change the System.Memory file to the upgraded version, the software I am using crashes on login because it uses the system.memory itself and can't work with the new version "produces the same error stated but reversed need 4.0.0.1" so its kinda dead locked as the application itself needs the old version and the dll needs the new version – yousif fayed Nov 29 '22 at 08:04
  • 1
    This is what binding redirects are for, if someone is requesting an older version of a dll it'll redirect it upward to the new version since older versions are guaranteed to run under newer versions. They should be generated automatically. Are you using nuget packages and in what format (packagereferce or package.config)? – Hank Nov 29 '22 at 15:58