Sicos1977 / MSGReader

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

System.PlatformNotSupportedException: System.Drawing is not supported on this platform. #234

Closed ddizh closed 4 years ago

ddizh commented 4 years ago

We are hosting our .netcoreapp 2.1 application on Azure App Service with x64 bit mode enabled. The way we publish our app is

dotnet publish --runtime win-x64 --no-self-contained

The MsgReader is referenced in one of our .netstandard2.0 projects like that:

<PackageReference Include="MsgReader" Version="3.7.24" />

This is what we get:

System.Drawing is not supported on this platform. ---> System.PlatformNotSupportedException: System.Drawing is not supported on this platform.
--- End of inner exception stack trace ---
at System.Drawing.SystemFonts.get_DefaultFont()
at MsgReader.Rtf.DocumentFormatInfo..ctor()
at MsgReader.Rtf.DomDocument.LoadRtfText(System.String)
at MsgReader.Outlook.Storage+Message.get_BodyHtml()

Note that it does work fine without the --runtime flag being set during publish. Any advises on how to fix this issue?

Sicos1977 commented 4 years ago

I have no idea, I never tested this on Azure.

Sicos1977 commented 4 years ago

I found this article on stack overflow --> https://stackoverflow.com/questions/51904125/azure-function-gives-error-system-drawing-is-not-supported-on-this-platform

A little update can help a lot of people. Now you can switch your Azure Function to v3: in Function app settings panel -> Runtime version ~3

With this setup, your code run in a sandbox that support Core 3, (you don't need to rebuild your dll to Core3, i run my .net core 2.1 dll without errors), and surprise... you don't get this exception anymore:

System.Drawing.Common: System.Drawing is not supported on this platform.

Because the CLI can found GDI/GDI+ that need in the subsystem. Now i can convert html to pdf without go crazy.
ddizh commented 4 years ago

For anyone having this same issue, this is how we solved it: the issue was that we didn't properly clear the publish folder. The old version of the library was stuck in that folder. So dotnet clean --output ... doesn't work in that case for whatever reason and we now remove publish output folder every time.

This has nothing to do with Azure or runtimes.