Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mailkit 3.4.3 / MsgReader 4.4.x compatibility #1495

Closed
ulued opened this issue Dec 28, 2022 · 6 comments
Closed

Mailkit 3.4.3 / MsgReader 4.4.x compatibility #1495

ulued opened this issue Dec 28, 2022 · 6 comments

Comments

@ulued
Copy link

ulued commented Dec 28, 2022

** I updated MsgReader from 3.2.1 to V4.4.2.
Mailkit 3.4.3 seems to have a dependency to System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1 while MsgReader 4.4.15 refers to System.Runtime.CompilerServices.Unsafe, Version=5.x.x.x probably through SixLabors.ImageSharp >= 2.1.3

Could you have a look and fix the dependencies?

**Platform **

  • OS: Windows
  • .NET Runtime: [e.g. CoreCLR, Mono]
  • .NET Framework: ,NET 4.7.2,
  • MailKit 3.4.3

Exception
exception: 0x1e84ccb - System.IO.FileLoadException: Die Datei oder Assembly "System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040)
bei MailKit.Net.Imap.ImapEngine.d__152.MoveNext()
bei MailKit.Net.Imap.ImapClient.d__108.MoveNext()
bei MailKit.Net.Imap.ImapClient.Connect(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)

To Reproduce
Steps to reproduce the behavior:

  1. Use Mailkit 3.4.3 and MsgReader 4.4.15 in one project
    2 create an IMAPClient Object
  2. Connect to a mailserver
  3. If I copy the "old" System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1 to the runtime directory imapclient.connect works,

Expected behavior
Connect should work with MsgReader 4.4.15, MailKit 3.4.x and System.Runtime.CompilerServices.Unsafe, Version=5.x.x.x

Code Snippets
If applicable, add code snippets to help explain your problem.
using (var client = new ImapClient())
{
try
{

                client.ServerCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => { return true; };
                client.CheckCertificateRevocation = false;
                client.Connect(m.ImapServer, m.ImapPort, m.ImapOptions); 
                // raises the execption 
@jstedfast
Copy link
Owner

This is effectively a duplicate of jstedfast/MimeKit#872

@jstedfast
Copy link
Owner

AFAICT, it's unfixable (by MimeKit/MailKit) because it all comes down to which other libraries you are using and which version(s) of System.Runtime.CompilerServices.Unsafe they depend on.

All of the stars need to align or it won't work.

...Unless you switch to .NET Core, then everything works fine.

@ulued
Copy link
Author

ulued commented Dec 29, 2022

The only thing I do is getting the MailKit and MsgReader packages from nuget and they don't work together any more.
This would imply, that MailKit / MsgReader is no longer usable together with Dot.Net 4.7.2.

But it seems using .Net 4.7.2 you are depending on it - there is a hint on https://stackoverflow.com/questions/62764744/could-not-load-file-or-assembly-system-runtime-compilerservices-unsafe
Could you reevaluate?

The bug that causes this issue is fixed in System.Runtime.CompilerServices.Unsafe 4.6.0. Use binding redirects, to load the specific version of the assembly that you need. Insert this snippet into all of your app.config files.

You need to specify the assembly version of the assembly that you need as newVersion. This is not the same as the package version that you choose when installing your NuGet package. They correspond like this:

Package 4.5.3 contains assembly version is 4.0.4.1
Package 4.7.0 contains assembly version 4.0.6.0
In this binding redirect I use the newer version of System.Runtime.CompilerServices.Unsafe that fixes the bug. However, if you depend on the older version, use 4.0.4.1.

@jstedfast
Copy link
Owner

https://stackoverflow.com/a/62769681/87117

The answer is correct, but it's not something that can be done in MimeKit or MailKit. It has to be done by you in your app project.

@ajtruckle
Copy link

Yes, I think that in my case the other NuGet package must have a reliance on an older Unsafe assembly that is not compatible with 6.0.0 So I am just stuck with the older MimeKit.

As mentioned by @jstedfast the proper solution is to see if the other NuGet vendor can upgrade Unsafe to 6.0.0 too. Or, you use the binding redirect approach you found out (assuming it will work - and it does not for me).

@ulued
Copy link
Author

ulued commented Jan 2, 2023

Neither is the "use the binding redirect approach" working for me (or I would not have opened an issue here). So I am stuck with MsgReader 3.2.1 until I migrate everything to 6.0.0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants