Sicos1977 / MSGReader

C# Outlook MSG file reader without the need for Outlook
http://sicos1977.github.io/MSGReader
MIT License
490 stars 168 forks source link

Object reference not set to an instance of an object when a font doesn't exist. #233

Closed sylvainrodrigue closed 3 years ago

sylvainrodrigue commented 4 years ago

For some mails we have received, MsgReader throw an "Object reference not set to an instance of an object" exception when trying to load the mail.

The problem begins in DomDocuments, line 794:long 809:

_fontChartset var fontName = FontTable.GetFontName(reader.Parameter);

In my case, FontTable contains 5 items and reader.Parameter == 5. The font is not found so MsgReader uses the default font, which is "Microsoft Sans Serif":

fontName = DefaultFontName;

The exception is thrown at the next line since FontTable[5] doesn't exist:

_fontChartset = FontTable[reader.Parameter].Encoding;

I suppose that fontChartset should use the default font encoding when the font doesn't exits. This is how I fixed it for my project.

Context: C# WebAPI usgin .NET Framework 4.6 on Windows 2016 server.

Note: MsgReader is a great tools, thank you to have made it open source!

Sicos1977 commented 4 years ago

Can you send me one of the mails that is giving the error? If so then please sent it to sicos2002@hotmail.com

Sicos1977 commented 4 years ago

No response, closed

sylvainrodrigue commented 4 years ago

Hi Sicos1977,

I sent the mail to you about 1 month ago.

Best regards, Sylvain.

Sicos1977 commented 3 years ago

Fixed in commit https://github.com/Sicos1977/MSGReader/commit/671c942aeaacde9d4ab20d8a599fb36a98cac454