Skip to content

System.Drawing.Common is not supported on non-Windows platforms #80148

Closed

Description

@qcjxberin

System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
at System.Drawing.LibraryResolver.EnsureRegistered() in System.Drawing.Common.dll:token 0x600058c+0x11
at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize() in System.Drawing.Common.dll:token 0x6000b00+0x0
at System.Drawing.SafeNativeMethods.Gdip..cctor() in System.Drawing.Common.dll:token 0x6000af8+0x2b

https://aka.ms/systemdrawingnonwindows can't be open,How to solve this problem

Activity

  1. svick commented on Aug 14, 2021

    @svick
    Member

    The exception message is correct: System.Drawing.Common is no longer supported on .Net 6 on Linux and macOS. For more information, see this document and dotnet/docs#25257.

    As that document states, if you want to continue using it on .Net 6, you can provide a runtime config switch named System.Drawing.EnableUnixSupport set to true. But even this will not work starting with .Net 7.

    As for the aka.ms link, I'm not sure. Maybe it will be set up once this breaking change is properly documented (i.e. when dotnet/docs#25367 is merged).

  2. mairaw commented on Aug 14, 2021

    @mairaw
    Contributor

    It seems @svick has answered your question, so I’m closing this issue. Let me know if I missed anything.

  3. reopened this on Aug 14, 2021
  4. mairaw commented on Aug 14, 2021

    @mairaw
    Contributor

    Reopening since the link goes to our internal tool somehow.
    Tagging @ericstj @danmoseley @terrajobst @safern who seem to own that link.

  5. safern commented on Aug 14, 2021

    @safern
    Member

    Tagging @ericstj @danmoseley @terrajobst @safern who seem to own that link.

    I'll work with @gewarren to post the doc ASAP on Monday and point the url to the doc.

  6. gewarren commented on Aug 16, 2021

    @gewarren
    Contributor

    @safern Here is the PR; it's ready for review: dotnet/docs#25367

  7. safern commented on Aug 16, 2021

    @safern
    Member
  8. added
    documentation
    on Aug 16, 2021
  9. janseris commented on Mar 16, 2022

    @janseris

    What is the solution for this for developers?
    I have a web server application running on Linux and I need to know what replaces System.Drawing for .NET 6 and later. I read in the documentation that

    recommended alternatives include ImageSharp, SkiaSharp, Windows Imaging Components, and Microsoft.Maui.Graphics.

    So now developers will use multiple libraries and .NET will have no standard image manipulation API at all?
    Which one of these is the right one? For which one Microsoft can guarantee support for the next years? What are we supposed to do when these random package authors change license or drop support?
    So now when people will want to learn .NET image manipulation, there will be package-specific tutorials?
    MAUI image API support might not be dropped but instead, it is a UI library so depending on MAUI on an ASP.NET server application which does not relate to MAUI in any way is ridiculous.
    What is the 1 and only suggested solution which will be supported by Microsoft just as .NET 6 is (LTS) etc.?

    What is the suggested solution for Blazor WebAssembly projects needing to resize image before uploading to server? MAUI graphics API?

    Thanks

  10. danmoseley commented on Mar 16, 2022

    @danmoseley
    Contributor

    @mattleibow can you confirm that SkiaSharp is fully supported by Microsoft?

    Also, I have generally thought of SkiaSharp as client focused, and something like ImageSharp better for servers. Is it reasonable to use SkiaSharp on the server side? I know that unlike ImageSharp, it has some native dependencies.

  11. siddjain commented on Dec 30, 2022

    @siddjain

    I am using System.Drawing.Common on Mac OS but with target framework 6.0 and have set

    {
      "runtimeOptions": {
        "tfm": "net6.0",
        "framework": {
          "name": "Microsoft.NETCore.App",
          "version": "6.0.0"
        },
    "configProperties": {
          "System.Drawing.EnableUnixSupport": true
       }
      }
    }
    

    but still seeing this exception:

    Unhandled exception. System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
       at System.Drawing.SystemFonts.get_DefaultFont()
    

    can anyone help please?

  12. gewarren commented on Dec 30, 2022

    @gewarren
    Contributor

    @siddjain Which file are those settings from?

  13. siddjain commented on Dec 30, 2022

    @siddjain

    the settings are from myapplication.runtimeconfig.json under bin/Debug/net6.0-windows of the project root. I am trying to run the application from the project root using dotnet run. Thanks for your help.

  14. 2 remaining items

  15. gewarren commented on Dec 30, 2022

    @gewarren
    Contributor

    Looks like you're using the 7.0 version of System.Drawing.Common. Does it work if you set that to 6.0.0?

  16. siddjain commented on Dec 30, 2022

    @siddjain

    no it still doesn't work

    Unhandled exception. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
     ---> System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
       at System.Drawing.LibraryResolver.EnsureRegistered()
       at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()
       at System.Drawing.SafeNativeMethods.Gdip..cctor()
       --- End of inner exception stack trace ---
       at System.Drawing.SafeNativeMethods.Gdip.GdipGetGenericFontFamilySansSerif(IntPtr& fontfamily)
       at System.Drawing.FontFamily.GetGdipGenericSansSerif()
       at System.Drawing.FontFamily.get_GenericSansSerif()
       at System.Drawing.Font.CreateFont(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte charSet, Boolean isVertical)
       at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
       at System.Drawing.Font..ctor(String familyName, Single emSize, String systemName)
       at System.Drawing.SystemFonts.get_DefaultFont()
    
  17. siddjain commented on Dec 30, 2022

    @siddjain

    made some changes and that error is fixed but I get a new one now:

    Unhandled exception. System.TypeInitializationException: The type initializer for 'Gdip' threw an exception.
     ---> System.DllNotFoundException: Unable to load shared library 'libgdiplus' or one of its dependencies. In order to help diagnose loading problems, consider setting the DYLD_PRINT_LIBRARIES environment variable: dlopen(liblibgdiplus, 0x0001): tried: 'liblibgdiplus' (no such file), '/System/Volumes/Preboot/Cryptexes/OSliblibgdiplus' (no such file), '/usr/lib/liblibgdiplus' (no such file, not in dyld cache), 'liblibgdiplus' (no such file), '/usr/local/lib/liblibgdiplus' (no such file), '/usr/lib/liblibgdiplus' (no such file, not in dyld cache)
       at System.Drawing.SafeNativeMethods.Gdip.GdiplusStartup(IntPtr& token, StartupInput& input, StartupOutput& output)
       at System.Drawing.SafeNativeMethods.Gdip..cctor()
    

    how do I fix this one?

  18. safern commented on Jan 3, 2023

    @safern
    Member

    @siddjain for that specific error you need to make sure that libgdiplus is installed in your OS.

    https://www.mono-project.com/docs/gui/libgdiplus/

    In Unix systems you can do it by running sudo apt-get install libgdiplus or whatever is the package manager for that OS.

    on mac systems you need to run brew install mono-libgddiplus

    Note that using 6.0.0 means that you'd be out of support so the recommended guidelines from the .NET team is to move out of depending on System.Drawing.Common for non windows.

  19. danmoseley commented on Jan 3, 2023

    @danmoseley
    Contributor

    @mattleibow just checking you saw my question above as it would be good to know the answer.

  20. transferred this issue fromdotnet/coreon Jan 3, 2023
  21. danmoseley commented on Jan 3, 2023

    @danmoseley
    Contributor

    @siddjain do you have to use System.Drawing? As mentioned, it is out of support now.

  22. siddjain commented on Jan 4, 2023

    @siddjain

    Thanks all for the help. re: do you have to use System.Drawing? to answer literally, its a loaded question. One can always port the code to another library. In fact, I already did it for one of my GDI+ apps as I wanted to learn Swift but to my surprise the C# code runs much faster than Swift!

    Also what I understand when someone says the library is out of support is that no one is fixing bugs and issues but anyone is welcome to use it as-is and it will continue to be available and downloadable from the internet. is that correct?

  23. danmoseley commented on Jan 4, 2023

    @danmoseley
    Contributor

    Also what I understand when someone says the library is out of support is that no one is fixing bugs and issues but anyone is welcome to use it as-is and it will continue to be available and downloadable from the internet. is that correct?

    System.Drawing is not going anywhere, but the code inside it that uses libgdiplus has been removed, which means that it will only work on Windows now.

    .NET 6 will go out of support in due course, although you'll still be able to download it if you don't mind being out of support.

    In short, I recommend you don't write code against System.Drawing unless it's only intended to run on Windows. The only exception might be if it's just a temporary thing, in which case you can use .NET 6. But generally you should pick another library to do this stuff unless you're Windows only.

  24. siddjain commented on Jan 4, 2023

    @siddjain

    Thanks Dan for the clarification!

  25. janseris commented on Jan 4, 2023

    @janseris

    @siddjain

    one can always port the code to another library

    This part is not magically for free you know especially with large codebase with little automatic tests

  26. siddjain commented on Jan 4, 2023

    @siddjain
  27. Rombersoft commented on Jan 7, 2023

    @Rombersoft

    Reading it all I came to the conclusion that I learned not the right programming language. It was necessary to learn Java 10 years ago when C# finished with such valuable problems. Microsoft is a great company but it is not able to make support graphics basics for three OS. I will keep silent about cross-platformed desktop GUI, they are missing. Miguel De Icaza come back. If you advise migrating to MAUI or Skia, maybe will you write a wrapper for it inside Linux System.Drawing implementation?

  28. ghost locked as resolved and limited conversation to collaborators on Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Drawingdocumentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions