SVG icon indicating copy to clipboard operation
SVG copied to clipboard

.NET 6 - System.Drawing.Common is no longer supported on non-Windows systems

Open dstj opened this issue 2 years ago • 10 comments

With .NET 6, System.Drawing.Common become a "Windows-only" dependency.

See this official Microsoft note about the breaking change. They it's mainly because libgdiplus used on Linux systems is "subpar".

SVG uses System.Drawing.Common, thus libgdiplus, so it's having issues with my docker image based on aspnet:6.0-alpine . Any plans to migrate to one of the recommended alternatives?

Recommended action To use these APIs for cross-platform apps, migrate to one of the following libraries:

ImageSharp SkiaSharp Microsoft.Maui.Graphics

-- Sidenote: the reason I got into this is because I have an alignment issue under Linux that I do not have under Windows.

image

The code relies on amountSvgText.Dx = new SvgUnitCollection { new(SvgUnitType.Pixel, CONSTANT - amountSvgText.Bounds.Width) }; and I believe the culprit is libgdiplus.

dstj avatar Dec 16 '21 23:12 dstj

Use https://github.com/wieslawsoltes/Svg.Skia

Happypig375 avatar Dec 30 '21 04:12 Happypig375

See also #910.

mrbean-bremen avatar Dec 30 '21 07:12 mrbean-bremen

Use https://github.com/wieslawsoltes/Svg.Skia

I want to create an SVG from scratch, not render a bitmap from an SVG. Svg.Skia doesn't do that.

dstj avatar Dec 30 '21 14:12 dstj

Likewise I think this code should add an .NET 6 TFM to it that does not reference manually:

  • System.ObjectModel (it already is referenced in Microsoft.NETCore.App)
  • System.Memory (also referenced in Microsoft.NETCore.App)
  • runtime.osx.10.10-x64.CoreCompat.System.Drawing (not needed and I think targeting 6.0 should make it "Windows only" by having the 6.0 tfm be: net6.0-windows)
  • System.Drawing.Common (can be eliminated by having the net6.0-windows target import the WindowsDesktop SDK manually (or have it set UseWindowsForms and/or UseWPF to true when '$(TargetFramework)' == 'net6.0-windows')

So then in the end the 6.0 target would be added to TargetFrameworks only when the build os is Windows and is windows only, imports the Desktop runtime for the 6.0 target and references only Fizzler / other dependencies that themselves have no dependencies.

For me it's annoying having to delete the osx files manually every time I rebuild my windows forms program so a 6.0 target is a must for me on this dependency of it (because I only want the Svg.dll and Fizzler.dll's copied to the compiled output folder).

AraHaan avatar Dec 30 '21 18:12 AraHaan

Likewise I think this code should add an .NET 6 TFM to it that does not reference manually:

It sounds as if you already have done this locally - you may make a PR in this case. If you only use net6.0-windows it would basically mean that 5.0 is (and will be) the last version supported for non-Windows systems. I'm not sure if there are other options, but for now it seems sensible.

CC @wieslawsoltes, @gvheertum

mrbean-bremen avatar Dec 30 '21 18:12 mrbean-bremen

The real issue is the removal of System.Drawing.Common breaks a lot of stuff and backwards compatibility and you have re-implement it using something else. See my attempt to just remove the dependency https://github.com/svg-net/SVG/pull/931

wieslawsoltes avatar Jan 02 '22 15:01 wieslawsoltes

I did try today Microsoft.Maui.Graphics with my Svg.Model (base library used by Svg.Skia) to implement basic svg rendering.

I have found several issues in that library: https://github.com/dotnet/Microsoft.Maui.Graphics/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+author%3Awieslawsoltes

The library is not that hard to use but lacks some features and definitely not as powerful as SkiaSharp.

image

wieslawsoltes avatar Jan 09 '22 19:01 wieslawsoltes

That looks cool, perhaps that can be split into Svg.Maui, and have the normal Svg package get killed off, with there being an Svg.WinForms which is then Windows only (does not reference the System.Drawing.Common package as it would reference the Windows Forms reference pack implicitly from the .NET Sdk) which would help me out as then I would only get the Svg.WinForms.dll file and the Fizzler dependency copied only so then I do not need to delete the OSX files manually on my program that is Windows only.

Or better yet, have the normal Svg package by itself an ".NET Sdk" that then determines if the program is a Windows Forms or WPF application or not and reference Svg.WinForms or Svg.Maui depending on what it finds.

AraHaan avatar Jan 10 '22 16:01 AraHaan

That looks cool, perhaps that can be split into Svg.Maui, and have the normal Svg package get killed off, with there being an Svg.WinForms which is then Windows only (does not reference the System.Drawing.Common package as it would reference the Windows Forms reference pack implicitly from the .NET Sdk) which would help me out as then I would only get the Svg.WinForms.dll file and the Fizzler dependency copied only so then I do not need to delete the OSX files manually on my program that is Windows only.

Or better yet, have the normal Svg package by itself an ".NET Sdk" that then determines if the program is a Windows Forms or WPF application or not and reference Svg.WinForms or Svg.Maui depending on what it finds.

The Microsoft.Maui.Graphics is not even close to being ready to use, it's buggy, missing basic features, unreleased and unsupported. Don't get your hopes high, it will take a lot of time until Microsoft.Maui.Graphics is ready maybe even 18 or more months or it can even be canceled.

wieslawsoltes avatar Jan 12 '22 09:01 wieslawsoltes

Due to the problem of memory non release in Linux, when can It release a new version?

wxdlt avatar May 12 '22 09:05 wxdlt