報錯:
System.PlatformNotSupportedException: System.Drawing.Common is not supported on non-Windows platforms. See https://aka.ms/systemdrawingnonwindows for more information.
> 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)
at QRCoder.QRCode.GetGraphic(Int32 pixelsPerModule, Color darkColor, Color lightColor, Boolean drawQuietZones)
at QRCoder.QRCode.GetGraphic(Int32 pixelsPerModule)
at x1yun.xyUnity.Exchanger.GerQrCodeStream(String paystr, Int32 pixels) in D:\x1yun\x1yunAPI\xyUnity\Exchanger.cs:line 1026
at x1yun.xyForeign.SenparcWx.WxpaymentSdk.getWxNativePayAsync(sev_order_record ordRecod) in D:\x1yun\x1yunAPI\xyForeign\SenparcWx\WxpaymentSdk.cs:line 92
解決:
構建專案時,會在輸出目錄中生成[appname].runtimeconfig.json檔案,只需要修改該配置檔案即可
例如 生成的 Test.Api.runtimeconfig.json 檔案
{
"runtimeOptions": {
"tfm": "net6.0",
"frameworks": [
{
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
{
"name": "Microsoft.AspNetCore.App",
"version": "6.0.0"
}
],
"configProperties": {
"System.GC.Server": true,
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
"System.Reflection.NullabilityInfoContext.IsSupported": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false,
"System.Drawing.EnableUnixSupport": true
}
}
}
沒有的話加上, "System.Drawing.EnableUnixSupport": true