System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode.
When running ASP.NET Core application in Docker, you may hit the following error:
System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'name')
This article provides solutions for this issue.
The image used doesn't support globalization while the ASP.NET Core application needs it. To address this issue, we need to use images that support globalization.
Internal Components for Unicode (ICU)
For many cases, we need ICU support and/or tzdata support. However, not all the published .NET Core images have these built-in. For example, only the following official published .NET container images that include ICU:
The following images do not include ICU:
Ubuntu chiseled images
To resolve this issue, we can either pick up the image with ICU built-in or add the support directly.
For example, if you are using
mcr.microsoft.com/dotnet/aspnet:7.0.4-alpine3.16, we can change it to
Alternatively, we can add support into Alpine images:
# final stage/imageFROM mcr.microsoft.com/dotnet/aspnet:7.0.4-alpine3.16 ENV \ DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ LC_ALL=en_US.UTF-8 \ LANG=en_US.UTF-8 RUN apk add --no-cache \ icu-data-full \ icu-libs
Please log in or register to comment.account_circle Log in person_add Register