System.Drawing.Common Alternatives (.NET 7 & Non-Windows)
Starting from .NET6, Microsoft has stopped supporting System.Drawing.Common on Linux and macOS. This library will now only work on Windows. For more details, refer to the official documentation.
Workarounds to Avoid system.drawing.common is not supported on this platform
.NET6
On non-Windows operating systems, a TypeInitializationException
is thrown with PlatformNotSupportedException
as the inner exception. The platform analyzer emits compile-time warnings for non-Windows platforms. The following runtime exception is thrown unless you set a configuration option:
System.TypeInitializationException : The type initializer for 'Gdip' threw an exception.
---- System.PlatformNotSupportedException : System.Drawing.Common is not supported on non-Windows platforms.
Temporary work-around in .NET6:
Enable support for non-Windows platforms by setting the System.Drawing.EnableUnixSupport
runtime configuration switch to true
in the runtimeconfig.json
file:
{
"runtimeOptions": {
"configProperties": {
"System.Drawing.EnableUnixSupport": true
}
}
}
Add the following code to the beginning of your code:
System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);
.NET7 and above
Starting from .NET7, Microsoft has completely removed support for System.Drawing.Common
on Linux and macOS, including the previously available workaround.
Iron Software has released an open-source replacement for System.Drawing.Common, called IronSoftware.Drawing
.
To learn more, visit the official documentation