System.TypeInitializationException: The type initializer for 'Gdip' threw an exception

Question: Has anyone found the fix for this issue yet? "

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()


Please Login to see the rest of the answer

Answer: If you are looking to generate images on Linux using C# or Asp.Net 6 inside a Docker Container, do not use any libraries. The libraries available online do not work (at least for me). The easiest way to generate Images on Linux using C# or Asp.Net Core is by using Stream.

Steps:

1. Read an Image as a Stream
    This can be accomplished by using System.IO.File.Read() or just Load the bytes from the 
    Binary Base64 String.

2. Use the "using directive" that allows you to clean up after completing using the Stream. 

3. Finally, using the SourceOfTheOriginalStream.CopyToAsync(""urlPath);
    and you are done.

4. If you happen to be in need of modifying the Image settings, then you might be out of luck doing that on Linux. You would need to use the Windows Server or some sort to accomplish that task.




Write an Article
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.


© 2022 - ErnesTech - Privacy