MailMessage.Load(inputStream, MailMessageFormat.Msg)

	readonly Dictionary<string, MailMessageFormat> EmailFormatMap = new Dictionary<string, MailMessageFormat>
	{
		{ "application/vnd.ms-outlook", MailMessageFormat.Msg },  // .msg formatı
		{ "message/rfc822", MailMessageFormat.Eml }              // .eml formatı
	};
MemoryStream inputStream = new MemoryStream();
FileManager.WriteToStream(FileContent, ref inputStream);
MailMessageFormat fileformat = EmailFormatMap.TryGetValue(ItemAttachment.FileType, out var format) ? format : MailMessageFormat.Eml;
var message = MailMessage.Load(inputStream, fileformat );

There is no problem when MailMessageFormat.Eml is passed as the second parameter to the Load method, but when MailMessageFormat.Msg is used, I get the following error.

System.Collections.Generic.KeyNotFoundException: 'The given key was not present in the dictionary

Thank you for your help!

Hi,

Please send us the MSG file that you’re loading into a MailMessage object so we can reproduce this issue and investigate it.

Regards,
Mario

Hi, I am currently evaluating Gembox.email and encountered the same issue when reading an Msg (Eml works fine): the given key ‘34068’ was not present in the dictionary. Any update on this?

Hi Johan,

Yes, this issue should be resolved in one of the newer versions.
Can you please try again with this latest package:

Install-Package GemBox.Email -Version 2025.4.110-hotfix

If the problem remains, please send us your MSG file so we can investigate it.

Regards,
Mario

Hi Mario,

Many thanks for the quick reply.
I can confirm that the fix works.

Best regards,
Johan