Resources for visualizing data using C# and the .NET platform
About the end of cross-platform support for System.Drawing.Common and what to do about it

History

  • System.Drawing started as a Windows-Only namespace
  • In 2018 the System.Drawing.Common package brought System.Drawing to cross-platform .NET Core projects
  • In 2021 the dotnet design team decided to only support Windows as a breaking change
  • In 2021 .NET 6 projects began warning CA1416: This call site is reachable on all platforms
  • In 2022 .NET 7 projects using System.Drawing.Common began throwing PlatformNotSupportedException

Why was cross-platform support dropped?

Summarizing Microsoft’s Reason for change,

  • Cross-platform support for System.Drawing.Common depends on libgdiplus

  • libgdiplus is a mess and Microsoft does not want to support it. It a large (30k line) C code base without tests and has numerous external dependencies (cairo, pango, etc.)

  • “It’s not viable to get libgdiplus to the point where its feature set and quality is on par with the rest of the .NET stack.”

  • “From analysis of NuGet packages … we haven’t noticed heavy graphics usage … [these projects are] typically well supported with SkiaSharp and ImageSharp.”

  • System.Drawing.Common will now only be developed for Windows Forms

What to do about it?

Target Windows

This problem is resolved if you update your csproj file to only target Windows:

<PropertyGroup>
  <TargetFramework>net6.0-windows</TargetFramework>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="System.Drawing.Common" />
</ItemGroup>

Use an Old Package and Silence the Warning

I think if you continue installing the .NET 5 version of the System.Drawing.Common package and edit your csproj file to silence the warning, you may get a little more life out of your existing project.

<PropertyGroup>
  <TargetFramework>net5.0</TargetFramework>
  <NoWarn>1416</NoWarn>
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="System.Drawing.Common" Version="5.*" />
</ItemGroup>

Use Another Graphics Technology

Quickstart guides are available on this website for:

  • SkiaSharp
  • Microsoft.Maui.Graphics
  • ImageSharp

Pro: These newer projects are more performant and thread-safe.

Con: It’s a lot of work to migrate to these platforms and it may require big changes to your project’s API.

Use System.Drawing.Primitives

To use a different rendering technology without breaking existing APIs it may be possible to use Color, Point, Rect, etc. from the System.Drawing.Primitives package which will continue cross-platform support but not contain any rendering capabilities.

References