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

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Curtis Chau
Escritor Técnico

Curtis Chau tiene una licenciatura en Ciencias de la Computación (Carleton University) y se especializa en el desarrollo front-end con experiencia en Node.js, TypeScript, JavaScript y React. Apasionado por crear interfaces de usuario intuitivas y estéticamente agradables, disfruta trabajando con frameworks modernos y creando manuales bien ...

Leer más
¿Listo para empezar?
Nuget Descargas 16,154,058 | Versión: 2025.11 recién lanzado