.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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库