Closed OliverSteinau closed 9 months ago
Did you register your encoding providers?
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
Why should I register encoding providers? I'm not using any encodings. And also, I'm trying to read "BodyHtml" which shouldn't need any.
The exception is thrown in line 195 in MSGReader/MsgReaderCore/Rtf/FontTable.cs:
public static Encoding DefaultEncoding { get; } = Encoding.GetEncoding("Windows-1252");
and I'm not accessing any Rtf stuff either. The complete code looks like this:
private void Test () {
using FileStream strm = new("d:/xx.msg", FileMode.Open, FileAccess.Read);
using Storage.Message msg = new(strm);
Debug.WriteLine(msg.BodyHtml);
}
Because HTML is embedded into RTF with encoding and that is why you need encoding providers.
Normally msg reader should register the encoding providers when it detects that you are running on .net core... so please try to register it and see if it fixes your problem.
Because HTML is embedded into RTF with encoding
Funnily, when I access "msg.BodyRtf", the error does not occur...
And yes, after calling
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
no exception is thrown.
As I said, this is on .NET 6
Because HTML is embedded into RTF with encoding
Funnily, when I access "msg.BodyRtf", the error does not occur...
And yes, after calling
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
no exception is thrown. As I said, this is on .NET 6
That is because you then get the RAW rtf and MSGReader does not try to get the HTML out of the RTF
the following code (on .NET 6.0):
throws the above TypeInitializationException (funnily enough, accessing msg.BodyRtf() doesn't...)
Stacktrace: