System.Drawing.Common Alternatives (.NET 7 & Non-Windows)

Starting with .NET 6, 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" Error

.NET 6

On non-Windows operating systems, a TypeInitializationException is thrown with a 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 .NET 6:

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
        }
    }
}

Additionally, add the following line at the beginning of your code to enable the configuration programmatically:

// Enable System.Drawing.Common support on non-Windows platforms in .NET 6
System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);
// Enable System.Drawing.Common support on non-Windows platforms in .NET 6
System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", true);
' Enable System.Drawing.Common support on non-Windows platforms in .NET 6
System.AppContext.SetSwitch("System.Drawing.EnableUnixSupport", True)
$vbLabelText   $csharpLabel

.NET 7 and above

Starting from .NET 7, 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.

Chaknith Bin
Software Engineer
Chaknith works on IronXL and IronBarcode. He has deep expertise in C# and .NET, helping improve the software and support customers. His insights from user interactions contribute to better products, documentation, and overall experience.