.netCore System.Drawing.Common 发布,在CentOS 运行报错,生成图片流时。会因为不支持在liunx平台生成图片。

报错:

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 

 

posted on 2024-06-04 14:37  侗家小蚁哥  阅读(21)  评论(0编辑  收藏  举报