Azure Function gives error: System.Drawing is not supported on this platform

It's not about the CLR, it's about the sandbox.

System.Drawing relies heavily on GDI/GDI+ to do its thing. Because of the somewhat risky nature of those APIs (large attack surface) they are restricted in the App Service sandbox.

Win32k.sys (User32/GDI32) Restrictions

For the sake of radical attack surface area reduction, the sandbox prevents almost all of the Win32k.sys APIs from being called, which practically means that most of User32/GDI32 system calls are blocked. For most applications this is not an issue since most Azure Web Apps do not require access to Windows UI functionality (they are web applications after all).

Try to find an different library that doesn't rely on System.Drawing/GDI, like ImageSharp.


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.