-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Breaking change]: System.Drawing.Common no longer supported on non-Windows OSs #25257
Comments
I will add source code examples on how to migrate from the most common scenarios tomorrow or the day after. |
@safern Do you still plan to add some code examples to this issue? |
Yes. Will do it today or tomorrow. I'll ping you when ready. |
@gewarren the template should add a new category of breaking change:
(which is the case for this one as it's neither a binary nor a source breaking change as defined above) |
Looks good to me! Thanks for getting this filed. |
@terrajobst After discussing with Mark Miller and Priya, we decided to expand the definitions of source/binary compatibility instead of adding a new category. Does this PR work for you?
|
Works and matches my intuition for binary compat |
@safern Is the namespace for the group that starts with AdjustableArrowCap incorrect? I could find those types under System.Drawing.Drawing2D but not System.Drawing.Design. |
@gewarren, yes! Good catch. I updated the issue 😄 |
Description
As proposed on: dotnet/designs#234
System.Drawing.Common is now attributed as a Windows specific library which will cause the platform analyzer to emit warnings when compiled for non-windows OSs.
At runtime on non-windows OSs will now throw by default a
TypeInitializerException
with aPlatformNotSupportedException
as the inner exception, unless a runtime config switch is set. The exception looks like this one:To enable Unix support, the runtime config switch,
System.Drawing.EnableUnixSupport
, needs to be set totrue
.Even if applications set the runtime config switch to
true
, this is just to give applications that heavily depend on this behavior cross plat, to migrate to more modern like libraries, and we will no longer give support for non-Windows bugs. This runtime config switch will be removed in .NET 7.The libraries that we recommend libraries to search as an alternative are:
Version
.NET 6 Preview 7
Previous behavior
There was no compile warnings.
There was no runtime exception and no need to set a runtime config switch.
New behavior
Type of breaking change
Reason for change
The cross-platform implementation of
System.Drawing.Common
is mainly providedon the native side, via
libgdiplus
. It's effectively a re-implementation ofthe parts of Windows that
System.Drawing.Common
is depending on. As you canimagine, that makes
libgdiplus
a very non-trivial component. It's around 30klines of pretty old C code, virtually untested, and lacks a lot of
functionality.
libgdiplus
also has a lot of external dependencies for all theimage processing and text rendering, such as
cairo
,pango
, and other nativelibraries, which makes maintaining and shipping it even more challenging.
Since
System.Drawing.Common
was really designed to be a thin wrapper overWindows technologies, its cross-platform implementation is a bit like a square
peg in a round hole; it's subpar because it was only designed with Windows in
mind.
Since the inclusion of the Mono cross-platform implementation we spent lot of
time redirecting issues to
libgdiplus
that never got fixed, or helping peopleinstall
libgdiplus
correctly (because it's not part of .NET Core proper). Thisis very different from other external dependencies we have taken, for example,
icu
oropenssl
, which are high-quality libraries, rather than poorlymaintained re-implementation of Windows components. Thus, we have come to
believe that it's not viable to get
libgdiplus
to the point where its featureset and quality is on par with the rest of the .NET stack.
We have noticed (such as from analysis of NuGet packages) that
System.Drawing.Common
is used on cross-platform mostly for image manipulationlike QR code generators and text rendering. We haven't noticed heavy graphics
usage as our cross-platform graphics support is very incomplete. For example,
right now some components crash on macOS because the native APIs we use have
been deprecated and are no longer included with recent macOS releases. We have
never gotten a report about that crash; we discovered it ourselves while making
System.Drawing.Common
trim compatible.The usages we see of
System.Drawing.Common
in non-Windows environments aretypically well supported with SkiaSharp and ImageSharp.
Thus, we believe it is not worth investing in making
System.Drawing.Common
work on non-Windows platforms and instead propose we only keep evolving it in
the context of Windows Forms and GDI+.
Recommended action
Migrate code to one of the previously recommended libraries.
TODO: add examples.
Feature area
Other (please put exact area in description textbox)
Affected APIs
Namespace:
System.Drawing
Namespace:
System.Drawing.Drawing2D
Namespace:
System.Drawing.Imaging
Namespace:
System.Drawing.Printing
Namespace:
System.Drawing.Text
cc: @ericstj @terrajobst @danmoseley
The text was updated successfully, but these errors were encountered: