Reading a UTF-7 formatted MSG

I have some code that reads MSG files. It works fine but we have a customer where it trips up with some of their files and throws an exception (see the attached screenshot).FZI2ssv8bJ.png (42.4 KB)

I’m not at liberty to share any of the customer’s emails unfortunately.

If you can’t view the image, here is the code fragment; it fails when calling MailMessage.Load()

// Now get the sent date of the MSG
                                    MailMessage thisMSG;
                                    thisMSG = MailMessage.Load(sFullPath);

The exceptions reads “Support for UTF-7 is disabled. See SYSLIB0001 warning - .NET | Microsoft Learn for more information”

This recommends the following which I have tried but I still get the exception:

// Disable the warning.
#pragma warning disable SYSLIB0001

// Code that uses obsolete API.
// ...

// Re-enable the warning.
#pragma warning restore SYSLIB0001

Could someone please advise.

Hello @Alec_M,

Did you try the following?

To suppress all the SYSLIB0001 warnings in your project, add a <NoWarn> property to your project file.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
   ...
   <NoWarn>$(NoWarn);SYSLIB0001</NoWarn>
  </PropertyGroup>
</Project>

Thanks for the advice Dmitry. As it happens I hadn’t tried that, but I have now and it has not made any difference. :slightly_frowning_face:

So I have now tried it with: the “NoWarn” edit to project file, the #pragma additions, and both. In all three cases the same exception is thrown.

Any suggestions on anything else to try?

Hello Alec,

Can you send us a file of such a message?
It may not contain a confidential data.
All we need is UTF-7 encoding and a reproducible exception.
We can make this topic private, if necessary.

Thanks.

Hi Dmitry, I got a colleague to build and test the same code on his machine and it appears to work as expected. We have more testing to do but the current indications are that the exceptions only occur when debugging on my machine.

Hi Alec,

Thank you for the information, let me know if you need any more assistance from us.

Hi Dmitry,

I’ve tried the #pragma and project settings too, but your ExtractMessage is still throwing the “Support for UTF-7 is disabled. See SYSLIB0001 warning - .NET | Microsoft Learn for more information.” exception at runtime.

MapiMessage message = personalStorage.ExtractMessage(messageId);

BTW I’m using an older version 17.12.0.

Hello @rhundhausen,

We have fixed this problem in recent versions, by forcing the use of UTF-8.
Unfortunately, older versions remain with this problem as Microsoft has deprecated this encoding.