Linux 问题处理:Set the configuration flag System.Globalization.

本文介绍了解决在Linux环境下部署的.NET Core应用程序遇到的全球化配置缺失问题的方法。通过修改runtimeconfig.json文件中的配置项System.Globalization.Invariant为true,解决了因缺少ICU包导致的应用程序运行失败的问题。
部署运行你感兴趣的模型镜像

背景:在linux上发布的.net core接口程序,在原有的服务器上是正常的,但拷贝程序到另一台服务器,运行程序时报错,错误信息如下:

Process terminated. Couldn't find a valid ICU package installed on the system. 
Set the configuration flag System.Globalization.
Invariant to true if you want to run with no globalization support.
   at System.Environment.FailFast(System.String)
   at System.Globalization.GlobalizationMode.GetGlobalizationInvariantMode()
   at System.Globalization.GlobalizationMode..cctor()
   at System.Globalization.CultureData.CreateCultureWithInvariantData()
   at System.Globalization.CultureData.get_Invariant()
   at System.Globalization.CultureInfo..cctor()
   at System.Globalization.CultureInfo.GetCultureInfoHelper(Int32, System.String, System.String)
   at System.Globalization.CultureInfo.GetCultureInfo(System.String)
   at System.Reflection.RuntimeAssembly.GetLocale()
   at System.Reflection.RuntimeAssembly.GetName(Boolean)
   at System.Reflection.Assembly.GetName()
   at System.AppDomain.get_FriendlyName()
   at NLog.Internal.Fakeables.AppDomainWrapper..ctor(System.AppDomain)
   at NLog.LogFactory.get_DefaultAppEnvironment()
   at NLog.LogFactory.get_CurrentAppDomain()
   at NLog.LogFactory..cctor()
   at NLog.LogFactory..ctor()
   at NLog.LogManager..cctor()
   at NLog.LogManager.GetLogger(System.String)
   at MideaCloud.SCADA.AutomationLine.Program.Main(System.String[])

解决方法:

需要修改项目的runtimeconfig.json 文件

1、找到文件

#进入发布文件夹,找到runtimeconfig.json文件
find ./ -name *runtimeconfig.json*

2、修改文件中的配置项

在configProperties中新建System.Globalization.Invariant项并设置为true,如下图

保存文件后重新运行程序,运行成功。

参考:https://docs.microsoft.com/zh-cn/dotnet/core/run-time-config/globalization

 

您可能感兴趣的与本文相关的镜像

Wan2.2-T2V-A5B

Wan2.2-T2V-A5B

文生视频
Wan2.2

Wan2.2是由通义万相开源高效文本到视频生成模型,是有​50亿参数的轻量级视频生成模型,专为快速内容创作优化。支持480P视频生成,具备优秀的时序连贯性和运动推理能力

using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PackingApp.Services { public class Logic { private DataRow[] _Rows; public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo"); private string dbConnectString = ConfigurationManager.AppSettings["Conn"].ToString(); public static OracleDBHelper dbHelper = new OracleDBHelper(dbConnectString); public static bool IsNewYear(string lastBoxNumber) { if (string.IsNullOrEmpty(lastBoxNumber) || lastBoxNumber.Length < 6) return true; // 如果格式不对,默认重新开始 string yearPart = lastBoxNumber.Substring(3, 2); // 取第4和5位作为年份 int boxYear = int.Parse(yearPart); int currentYear = DateTime.Now.Year % 100; // 当前年份后两位 return boxYear < currentYear; } public static async Task<DateTime> GetSysTime() { try { return DateTime.Parse((await dbHelper.ExecuteQueryAsync("SELECT TO_CHAR(SYSDATE, 'YYYY-MM-DD HH24:MI:SS') FROM DUAL")).Rows[0][0].ToString()); } catch { return DateTime.Now; } } private bool ProcessSystemMacro(string[] param, out string value) { value = null; bool flag = false; int num = 1; DateTime dateTime = GetSysTime(); if (value != null) { return true; } string text = _Rows[0]["PRODTYPE"].ToString().Split('|').Last(); switch (param[0]) { case "YYYY": value = dateTime.ToString("yyyy"); break; case "YY": value = dateTime.ToString("yy"); break; case "Y": value = dateTime.ToString("y"); break; case "MM": value = dateTime.ToString("MM"); break; case "DD": if (flag) { value = $"{dateTime.Day:00}"; } else { value = dateTime.ToString("dd"); } break; case "DDD": value = dateTime.DayOfYear.ToString(); while (value.Length < 3) { value = "0" + value; } break; case "WEEK": { Calendar calendar = CultureInfo.InvariantCulture.Calendar; value = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString(); break; } case "DOW": value = dateTime.DayOfWeek.ToString(); break; case "GEELYLOT": if (flag) { value = $"{dateTime:yyMM}{2 * (dateTime.Day - 1) + num:00}"; } break; case "ERPTAG": { string text2 = (_Rows[1].Table.Columns.Contains("SUFFIX") ? _Rows[1]["SUFFIX"].ToString() : ""); string text3 = string.Join("-", (!string.IsNullOrEmpty(_Rows[2]["ERP_PARTNO"] as string)) ? new string[3] { _Rows[2]["line"].ToString(), _Rows[2]["ERP_PARTNO"].ToString(), _Rows[1]["PACKID"].ToString().Replace("|", string.Empty) } : new string[3] { _Rows[2]["line"].ToString(), _Rows[2]["PARTNO"].ToString(), _Rows[1]["PACKID"].ToString().Replace("|", string.Empty) }); string text4 = "FGLABEL2"; string text5 = (string.IsNullOrEmpty(_Rows[2]["ERP_PARTNO"] as string) ? (_Rows[2]["PARTNO"].ToString() + text2) : (_Rows[2]["ERP_PARTNO"].ToString() + text2)); string empty = string.Empty; string empty2 = string.Empty; string text6 = _Rows[1]["CURRQUANTITY"].ToString(); string empty3 = string.Empty; string text7 = Process(new string[1] { "PLOT" }); string text8 = string.Empty; string empty4 = string.Empty; string text9 = _Rows[2]["rev"].ToString(); value = "(" + string.Join("|", text3, text4, text5, empty, empty2, text6, empty3, text8, empty4, text9) + ")"; string text10 = "insert into acc_pack_tag(ctime, packid, tag_name, tag_value) values(sysdate, :1, 'AssociatedERPTAG', :2)"; try { dbHelper.ExecuteNonQuery(text10, _Rows[1]["PACKID"].ToString(), value); } catch (Exception ex) { loginfo.Info(string.Format("Exception on executing: {0} with packid({1}) and value({2}) as below{3} {4}", text10, _Rows[1]["PACKID"], value, Environment.NewLine, ex.ToString())); } break; } default: return false; } return true; } public string Process(string[] param) { param[0] = param[0].ToUpper(); if (ProcessSystemMacro(param, out var value)) { return value; } try { string text = ((_Rows.Length > 1 && _Rows[1].Table.Columns.Contains("SUFFIX")) ? _Rows[1]["SUFFIX"].ToString() : ""); string text2 = _Rows[0]["PRODTYPE"].ToString().Split('|').Last(); for (int i = 0; i < _Rows.Length; i++) { if (_Rows[i].Table.Columns.Contains(param[0])) { if (param[0] == "PARTNO") { return string.Concat(_Rows[i][param[0]], text); } return _Rows[i][param[0]].ToString(); } if (_Rows[i].Table.Columns.Contains(text2 + "|" + param[0])) { return _Rows[i][text2 + "|" + param[0]].ToString(); } } } catch { return param[0]; } return param[0]; } public class ScanItem { public int Index { get; set; } public string PackID { get; set; } public DateTime PackDate { get; set; } public string PackBarcode { get; set; } } public class PackInfo { public string PackId { get; set; } public string PackSize { get; set; } } } } 字段初始值设定项无法引用非静态字段、方法或属性“Logic.dbConnectString”无法将类型“System.Threading.Tasks.Task<System.DateTime>”隐式转换为“System.DateTime”“ExecuteNonQuery”方法没有采用 3 个参数的重载
09-04
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zouzh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值