将.net 8 web.API发布到Azure导致错误:System.Globalization.CultureNotFoundException:尝试打开SQL连接时

q5lcpyga  于 2023-11-21  发布在  .NET
关注(0)|答案(1)|浏览(492)

我已经在.net 8中发布了一个c# web.API到一个azure web.API资源。
当我打开到SQL的连接时,我遇到了以下错误:

  1. System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
  2. en-us is an invalid culture identifier.
  3. at System.Globalization.CultureInfo.GetCultureInfo(String name)
  4. at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
  5. at Microsoft.Data.SqlClient.SqlConnection.InternalOpenAsync(CancellationToken cancellationToken)

字符串
我在项目属性中设置了以下内容:

  1. <PropertyGroup>
  2. <TargetFramework>net8.0</TargetFramework>
  3. <Nullable>disable</Nullable>
  4. <ImplicitUsings>enable</ImplicitUsings>
  5. <InvariantGlobalization>false</InvariantGlobalization>
  6. </PropertyGroup>


这在当地有效。
当我发布到Azure并查看Azure上的文件时,我在runtimeconfig.json中注意到:
{“runtimeOptions”:{“tfm”:“net8.0”,“frameworks”:[ {“name”:“Microsoft.NETCore.App”,“version”:“8.0.0”},{“name”:“Microsoft.AspNetCore.App”,“version”:“8.0.0”} ],“属性”:{“System.GC.Server”:true,“System.Globalization.Invariant”:true,“System.Globalization.PredefinedCulturesOnly”:true,“System.Reflection.Metadata.MetadataUpdater.IsSupported”:false,“System. Reflection.Serialization. EnableUnsafeBinarySerialization”:false } } }
我在.net 6示例上运行时没有这个问题。有人能帮助我并解释我应该如何解决我的问题吗?
非常感谢提前。
罗布

xkftehaa

xkftehaa1#

根据文档,.NET 8现在默认为globalization invariant mode,如果你不指定为detailed here.
为了启用对区域性的访问,您需要更新以下设置之一:
runtimeconfig.json

  1. {
  2. "runtimeOptions": {
  3. "configProperties": {
  4. "System.Globalization.Invariant": false
  5. }
  6. }
  7. }

字符串
Project file

  1. <Project Sdk="Microsoft.NET.Sdk">
  2. <PropertyGroup>
  3. <InvariantGlobalization>false</InvariantGlobalization>
  4. </PropertyGroup>
  5. </Project>


More documentation here regarding Globalization configuration.

展开查看全部

相关问题