admin管理员组文章数量:1125978
I was having an issue, which others have also had, when using MailKit 4.8.0 whereby when attempting to create an instance of MimeMessage, I got a FileLoadException complaining that the version of System.Runtime.CompilerServices.Unsafe was incorrect, and I was attempting to correct it using .exe.config and .dll.config files to correct the version numbers. Then MailKit and MimeKit 4.9.0 were released, so I updated, hoping that it might help with the issues I was having. Unfortunately, I now have an issue before reaching the creation of the MimeMessage, where calling SmtpClient.Connect causes a FileLoadException:
System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly 'System.Buffers, Version=4.6.0.0, 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)
Source=MailKit
StackTrace:
at MailKit.ByteArrayBuilder..ctor(Int32 initialCapacity)
at MailKit.Net.Smtp.SmtpStream.ReadResponse(CancellationToken cancellationToken)
at MailKit.Net.Smtp.SmtpClient.PostConnect(Stream stream, String host, Int32 port, SecureSocketOptions options, Boolean starttls, CancellationToken cancellationToken)
at MailKit.Net.Smtp.SmtpClient.Connect(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)
at ISolCommExtMAPI.SMTPMail64.Send() in C:\IPS\v25.1\Source\Components\IrisCommsProjects\ISolCommExtMAPI\ISolCommExtMAPI\SMTPMail64.cpp:line 68
Inner Exception 1:
FileLoadException: Could not load file or assembly 'System.Buffers, Version=4.0.4.0, 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)
The Exception Message contains the newVersion number specified in my config files, which is the minimum requirement listed in the nuget dependencies. I am learning as I go regarding assembly versioning, so any suggestions as to how to correct this situation would be gratefully received.
Just in case it makes any difference, the source code is written in C++.
SmtpClient^ client = nullptr;
try
{
//specify SMTP Server
client = gcnew SmtpClient();
client->RequireTLS = true;
// MailKit 4.9 throws FileLoadException here:
client->Connect(_emSMTPServer, _emSMTPPort, MailKit::Security::SecureSocketOptions::StartTls, System::Threading::CancellationToken::None);
NetworkCredential^ credentials = gcnew NetworkCredential(_emUserName, _emPassword);
client->Authenticate(System::Text::Encoding::UTF8, credentials, System::Threading::CancellationToken::None);
// MimeKit 4.8 threw FileLoadException here:
message = gcnew MimeMessage();
// ...
}
I've added:
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.6.0.0" newVersion="4.6.0.0" />
</dependentAssembly>
to the .exe.config file, and tried adding .dll.config files for all the relevant dll files with the same assemblyBinding. I still get the exception, with the difference in version numbers between the exception message and inner exception. I had the same issue previously with System.Runtime.CompilerServices.Unsafe.
I was having an issue, which others have also had, when using MailKit 4.8.0 whereby when attempting to create an instance of MimeMessage, I got a FileLoadException complaining that the version of System.Runtime.CompilerServices.Unsafe was incorrect, and I was attempting to correct it using .exe.config and .dll.config files to correct the version numbers. Then MailKit and MimeKit 4.9.0 were released, so I updated, hoping that it might help with the issues I was having. Unfortunately, I now have an issue before reaching the creation of the MimeMessage, where calling SmtpClient.Connect causes a FileLoadException:
System.IO.FileLoadException
HResult=0x80131040
Message=Could not load file or assembly 'System.Buffers, Version=4.6.0.0, 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)
Source=MailKit
StackTrace:
at MailKit.ByteArrayBuilder..ctor(Int32 initialCapacity)
at MailKit.Net.Smtp.SmtpStream.ReadResponse(CancellationToken cancellationToken)
at MailKit.Net.Smtp.SmtpClient.PostConnect(Stream stream, String host, Int32 port, SecureSocketOptions options, Boolean starttls, CancellationToken cancellationToken)
at MailKit.Net.Smtp.SmtpClient.Connect(String host, Int32 port, SecureSocketOptions options, CancellationToken cancellationToken)
at ISolCommExtMAPI.SMTPMail64.Send() in C:\IPS\v25.1\Source\Components\IrisCommsProjects\ISolCommExtMAPI\ISolCommExtMAPI\SMTPMail64.cpp:line 68
Inner Exception 1:
FileLoadException: Could not load file or assembly 'System.Buffers, Version=4.0.4.0, 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)
The Exception Message contains the newVersion number specified in my config files, which is the minimum requirement listed in the nuget dependencies. I am learning as I go regarding assembly versioning, so any suggestions as to how to correct this situation would be gratefully received.
Just in case it makes any difference, the source code is written in C++.
SmtpClient^ client = nullptr;
try
{
//specify SMTP Server
client = gcnew SmtpClient();
client->RequireTLS = true;
// MailKit 4.9 throws FileLoadException here:
client->Connect(_emSMTPServer, _emSMTPPort, MailKit::Security::SecureSocketOptions::StartTls, System::Threading::CancellationToken::None);
NetworkCredential^ credentials = gcnew NetworkCredential(_emUserName, _emPassword);
client->Authenticate(System::Text::Encoding::UTF8, credentials, System::Threading::CancellationToken::None);
// MimeKit 4.8 threw FileLoadException here:
message = gcnew MimeMessage();
// ...
}
I've added:
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.6.0.0" newVersion="4.6.0.0" />
</dependentAssembly>
to the .exe.config file, and tried adding .dll.config files for all the relevant dll files with the same assemblyBinding. I still get the exception, with the difference in version numbers between the exception message and inner exception. I had the same issue previously with System.Runtime.CompilerServices.Unsafe.
Share Improve this question asked 2 days ago Richard SandsRichard Sands 112 bronze badges New contributor Richard Sands is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.1 Answer
Reset to default 0Sigh. I was hoping v4.9.0 would fix the last of these issues since it was finally possible for all of the nuget dependencies to align with their System.Memory, System.Buffers, and System.Runtime.CompilerServices.Unsafe nuget package versions. Alas, here we are...
Based on the exception message, it appears that the dotnet runtime is failing to load System.Buffers, Version=4.0.4.0
but your assembly mapping maps it to 4.6.0.0. Perhaps the app.config needs to be changed to make a slightly different mapping?
<dependentAssembly>
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.6.0.0" newVersion="4.0.4.0" />
</dependentAssembly>
I'm pretty sure app.config mappings care about assembly versions and not nuget package versions, so the above XML might be the correct mapping. At the very least, you could give it a try and see what new error you get (if any).
Update:
Okay, I just noticed that I was looking at the inner exception where it tries to load 4.0.4.0. But the outer exception has it trying to load 4.6.0.0 and that also fails.
My next suggestion is to make sure that System.Buffers.dll
is being copied into your bin
directory. While you are doing that, check what the assembly version of that file is as well.
本文标签:
版权声明:本文标题:.net 4.8 - Updated from MailKit 4.8.0 to MailKit 4.9.0 because of FileLoadExceptions and now have similar issue in System.Buffer 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736662713a1946496.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论