Sunday, 25 May 2025

Resolve "System.NotSupportedException: Globalization Invariant Mode is not supported" in Microsoft.Data.SqlClient with Alpine Docker Image

 You may encounter exception "System.NotSupportedException: Globalization Invariant Mode is not supported" in Microsoft.Data.SqlClient in Linux Alpine docker images. Exception details are as below.

fail: Poc.Common.Api.Middleware.GlobalExceptionHandlerMiddleware[0]      Unexpected error occurred.      System.NotSupportedException: Globalization Invariant Mode is not supported.         at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)         at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)         at Microsoft.Data.SqlClient.SqlConnection.Open()         at Poc.Domain.Core.Implementation.Sql.SqlCommanRunner.RunAsync(String command) in /build/src/Shared/Domain/Poc.Domain.Core/Implementation/Sql/SqlCommanRunner.cs:line 20



This exception occures due to Alpine images by defualt does not have globalization support. To eable globalization support for Alphine docker images and run .NET applications with SqlClient  add the below to your base docker image.

FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine3.18-amd64 AS base
WORKDIR /app

ENV ASPNETCORE_URLS=http://+:80
EXPOSE 80

# Enable access to culture data for alpine docker image
# Add International Components for Unicode (ICU)
# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md
RUN apk add --no-cache icu-data-full icu-libs
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false

No comments:

Popular Posts