codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.66k stars 1.11k forks source link

The type initializer for 'Gdip' threw an exception. #389

Open SpringHgui opened 2 years ago

SpringHgui commented 2 years ago

Type of issue

[ x] Bug
[ ] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

Behavior

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.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, IntPtr scan0, IntPtr& bitmap)

https://docs.microsoft.com/en-us/dotnet/core/compatibility/core-libraries/6.0/system-drawing-common-windows-only

jtammaro commented 2 years ago

+1

uziruk commented 2 years ago

+1, I believe this has to do with microsoft droping system.drawing support on non windows oses. Maybe it could be replaced with imagesharp?

JoseAFerrer commented 2 years ago

+1, but I thought it had something to do with my system being an Apple M1. I'll keep working on it and let you know if I manage to solve it.

namespacedevbox commented 2 years ago

temporary solution, create runtimeconfig.template.json

{
   "configProperties": {
      "System.Drawing.EnableUnixSupport": true
   }
}
tkggusraqk commented 1 year ago

The aarch64 schema test is invalid

"error":{"ClassName":"System.TypeInitializationException","Message":"The type initializer for 'Gdip' threw an exception.","Data":null,"InnerException":{"ClassName":"System.PlatformNotSupportedException","Message":"System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at System.Drawing.LibraryResolver.EnsureRegistered()\n at System.Drawing.SafeNativeMethods.Gdip.PlatformInitialize()\n at System.Drawing.SafeNativeMethods.Gdip..cctor()","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2146233031,"Source":"System.Drawing.Common","WatsonBuckets":null},"HelpURL":null,"StackTraceString":" at System.Drawing.SafeNativeMethods.Gdip.GdipCreateBitmapFromScan0(Int32 width, Int32 height, Int32 stride, Int32 format, IntPtr scan0, IntPtr& bitmap)\n at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)\n at QRCoder.QRCode.GetGraphic(Int32 pixelsPerModule, Color darkColor, Color lightColor, Boolean drawQuietZones)\n at Zwt.MvcAdmin.Controllers.HomeController.CreateQR(String baseUrl, String content)\n

error