背景:在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