I've been using Mailkit 2.15 and now trying to upgrade to v3.4.1. When I upgraded, all its dependencies got installed including System.Runtime.CompilerServices.Unsafe v4.5.3. But when I execute the code, the following exception occurs.
13-Oct-2022 16:33:19,303 [INFO ] Mail SendEmail - System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
File name: 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.Span`1..ctor(T[] array)
at MimeKit.Utils.ValueStringBuilder..ctor(Int32 initialCapacity)
at MimeKit.Utils.Rfc2047.Encode(FormatOptions options, Encoding charset, String text, Boolean phrase)
at MimeKit.Header.EncodeUnstructuredHeader(ParserOptions options, FormatOptions format, Encoding encoding, String field, String value)
at MimeKit.Header.EncodeAddressHeader(ParserOptions options, FormatOptions format, Encoding encoding, String field, String value)
at MimeKit.Header.FormatRawValue(FormatOptions format, Encoding encoding, String value)
at MimeKit.Header.SetValue(FormatOptions format, Encoding encoding, String value)
at MimeKit.Header..ctor(Encoding encoding, HeaderId id, String value)
at MimeKit.HeaderList.set_Item(HeaderId id, String value)
at MimeKit.MimeMessage..ctor()
When I investigated further, I noticed that the MimeKit requires System.Memory and the System.Memory installed System.Runtime.CompilerServices.Unsafe v4.5.3. But I'm not sure why [System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1] is still required.
Note: Prior to Mailkit 3.4.1 upgrade, my project does not depend on System.Runtime.CompilerServices.Unsafe and it is not listed in the references.