Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
493 views
in Technique[技术] by (71.8m points)

mailkit - MimeKit .Net Core : The target process exited with code -1073741819 while evaluating the function "MimeKit.MimeMessage.ToString"

I am using Mimekit/Mailkit to forward mail in my .Net core app. The system exits with the following error : The target process exited with code -1073741819 while evaluating the function "MimeKit.MimeMessage.ToString"

While executing these lines:

   var builder = new BodyBuilder();
   builder.TextBody = forwardMail.Body ?? string.Empty;
   builder.Attachments.Add(new MessagePart { Message = message });
   message.Body = builder.ToMessageBody();

It is happening all the time. Why is this? How can I fix this issue ?

question from:https://stackoverflow.com/questions/66047428/mimekit-net-core-the-target-process-exited-with-code-1073741819-while-evalua

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You are making the message recursive.

message.Body = something that embeds message

When you call ToString() on it, the message gets written first to a MemoryStream (and from there, gets converted into a string) and the MemoryStream buffer must continue growing without bounds because there is no end to a recursive message.

You likely meant to embed a different message, but your code has a body part of the message pointing back to the top-level message again resulting in an infinite loop when it gets written out.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...