简体   繁体   English

Azure 应用服务似乎在 .NET 5 模式下启用了 NLS

[英]Azure App Service seems to have NLS enabled in .NET 5 mode

After spending countless of hours on getting to the core of a bug, I eventually boiled down a problem to the use of string.Compare with StringComparison.InvariantCultureIgnoreCase in .NET 5.在花了无数个小时来了解错误的核心之后,我最终将问题string.Compare为在 .NET 5 中使用string.CompareStringComparison.InvariantCultureIgnoreCase

Consider the following two dotnetfiddles:考虑以下两个 dotnetfiddle:

When running the .NET 4.7.2 you get -1 as a result, when running .NET 5 you get 1 as a result.运行 .NET 4.7.2 时,结果为 -1,运行 .NET 5 时,结果为 1。

After some browsing, this led to the following notice:经过一番浏览,这导致了以下通知:

So, going by this, a result of -1 is the NLS version, whereas the .NET 5 result of 1 is the ICU version.所以,按照这个,-1 的结果是 NLS 版本,而 1 的 .NET 5 结果是 ICU 版本。

However, when I spin up an Azure App Service in .NET 5 mode, the result of the above code in a Razor page is -1, AKA: the NLS version.但是,当我在 .NET 5 模式下启动 Azure 应用服务时,上述代码在 Razor 页面中的结果是 -1,也就是:NLS 版本。

This can cause all kinds of weird issues, because two different systems lead to unexpected results.这可能会导致各种奇怪的问题,因为两个不同的系统会导致意想不到的结果。

When I add add the following to my project-file, as mentioned in the last article, my local environment also outputs a -1.当我将以下内容添加到我的项目文件中时,如上一篇文章所述,我的本地环境也输出 -1。

<ItemGroup>
  <RuntimeHostConfigurationOption Include="System.Globalization.UseNls" Value="true" />
</ItemGroup>

No matter what kind of configuration I use in Azure, it will always keep outputting -1.无论我在 Azure 中使用什么样的配置,它都会一直输出 -1。

Long story, something is up on Azure.说来话长,Azure 出了点问题。 As per documentation, my Windows version is new enough to have ICU enabled.根据文档,我的 Windows 版本足够新,可以启用 ICU。 Looks like the Azure App Service is either using a forced NLS mode, or is running some ICU version my local machine doesn't have.看起来 Azure 应用服务要么使用强制 NLS 模式,要么正在运行我的本地机器没有的某些 ICU 版本。

Anyone know how I can figure out which ICU version (if any) Azure is using, so I can use the suggestion from the documentation to use a AppLocalIcu?任何人都知道我如何确定 Azure 正在使用哪个 ICU 版本(如果有),以便我可以使用文档中的建议来使用 AppLocalIcu? Otherwise, if something is clearly on the side of Azure, then my question is what the best location would be to report this?否则,如果 Azure 方面显然有某些事情,那么我的问题是报告此内容的最佳位置是什么?

I think you can use this method to enable the App-local ICU in the Azure app service.我觉得可以用这个方法在Azure应用服务中启用App-local ICU。

If your web app is a framework-dependent application, you can consume ICU via a NuGet package.如果您的 Web 应用程序是依赖于框架的应用程序,则可以通过 NuGet 包使用 ICU。

  • Install the NuGet package Microsoft.ICU.ICU4C.Runtime in your web app project.Web 应用项目中安装 NuGet 包Microsoft.ICU.ICU4C.Runtime
  • Edit the project file to add <RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="<suffix>:<version> or <version>" /> in the section <ItemGroup> .编辑项目文件以在<ItemGroup>部分添加<RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="<suffix>:<version> or <version>" /> <ItemGroup> Or you can add an app setting DOTNET_SYSTEM_GLOBALIZATION_APPLOCALICU with the value <suffix>:<version> or <version> .或者,您可以添加一个应用设置DOTNET_SYSTEM_GLOBALIZATION_APPLOCALICU ,其值为<suffix>:<version><version>

Then you can use the special version of ICU in the Azure App Service as you want.然后,您可以根据需要在 Azure 应用服务中使用特殊版本的 ICU。

Someone at the Azure App Service team dove into this: Azure 应用服务团队的某个人对此深有体会:

  • Most Azure App Services run on Windows 2016, more specifically at the time of writing:大多数 Azure 应用服务在 Windows 2016 上运行,更具体地说是在撰写本文时:
Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      14393  0   
  • In the Windows Server landscape ICU was introduced in Windows Server 2019.在 Windows Server 环境中,ICU 是在 Windows Server 2019 中引入的。

So to answer my own question: Azure App Services are indeed using NLS by default.所以回答我自己的问题:Azure 应用服务确实在默认情况下使用 NLS。 This is not a bug!这不是错误!

By including the following in your project-file, ICU will be forced:通过在您的项目文件中包含以下内容,ICU 将被强制执行:

<ItemGroup Condition="'$(OS)' == 'Windows_NT'">
  <PackageReference Include="Microsoft.ICU.ICU4C.Runtime" Version="68.2.0.9" />
  <RuntimeHostConfigurationOption Include="System.Globalization.AppLocalIcu" Value="68.2" />
</ItemGroup>

This is in line with the solution that @Crazy Crab mentioned, thanks!这与@Crazy Crab 提到的解决方案一致,谢谢!

Also see https://www.nuget.org/packages/Microsoft.ICU.ICU4C.Runtime for the latest version (68.2.0.9 at the time of writing).另请参阅https://www.nuget.org/packages/Microsoft.ICU.ICU4C.Runtime了解最新版本(撰写本文时为 68.2.0.9)。

I'm going to accept my own answer, as I feel it gives a better answer to the "Why is this happening" question, rather than just fixing it.我将接受我自己的答案,因为我觉得它可以更好地回答“为什么会发生这种情况”的问题,而不仅仅是修复它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JsonProperty似乎无法在Windows Azure应用程序服务上运行 - JsonProperty seems to not working on a windows azure app service 不幸的是,我有一个连接到交换 Web 服务的 azure 函数,使用的服务帐户启用了 MFA - I have an azure functions that connect to exchange web service unfortunately the service account used has MFA enabled Azure 应用服务 - 更新 .NET Core 运行时 - Azure App Service - update .NET Core runtime ASP.NET Core应用到Azure应用服务上的Linux - ASP.NET Core app to Linux on Azure App Service Azure 是否有用于应用服务域和 SSL 测试的沙箱? - Does Azure have a sandbox for App Service Domain and SSL testing? 确定是否在 Azure 服务总线队列上启用了会话 - Determine if sessions are enabled on an Azure Service Bus Queue 查找 Azure 服务总线队列上是否启用了 session - Find if session is enabled on Azure Service Bus Queue 在.Net核心控制台应用程序中使用Azure Service Bus - Using Azure Service Bus in .Net core console app Web.config 用于 .net 部署到 Azure 应用服务 - Web.config for .net deployment to Azure app service Azure Service Fabric中的ASP.NET Core应用程序中的WebpackDevMiddleware - WebpackDevMiddleware in ASP.NET Core app in Azure Service Fabric
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM