System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode.

Raymond Raymond event 2023-04-25 visibility 4,253
more_vert

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.

Root cause

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:

  • Alpine sdk images

  • Debian images

  • Ubuntu images

The following images do not include ICU:

  • Alpine aspnet, monitor, runtime, runtime-deps images

  • Ubuntu chiseled images

Resolutions

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 mcr.microsoft.com/dotnet/aspnet:7.0.5-bullseye-slim.  


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


References

Enabling (or disabling) globalization functionality

More from Kontext
comment Comments
No comments yet.

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts