"CultureNotFoundException: Culture is not supported. (Parameter 'culture') 1031 (0x0407) is an invalid culture identifier." on Docker/Kubernetes

Hello,

based on this example code, we are evaluating to sign MS Excel files using ASP.NET Core 3.1 on Docker/Kubernetes. While this works with some files, we test it with a file from our users where we got the following exception:

CultureNotFoundException: Culture is not supported. (Parameter ‘culture’) 1031 (0x0407) is an invalid culture identifier.

The full exception is:

System.Globalization.CultureNotFoundException: Culture is not supported. (Parameter 'culture')
1031 (0x0407) is an invalid culture identifier.
   at System.Globalization.CultureData.GetCultureData(Int32 culture, Boolean bUseUserOverride)
   at System.Globalization.CultureInfo..ctor(Int32 culture, Boolean useUserOverride)
   at ​​.(Int16 )
   at Aspose.Cells.CustomImplementationFactory.CreateCultureInfo(Int32 lcid)
   at ​​.(CountryCode )
   at  ​.(CountryCode )
   at Aspose.Cells.WorkbookSettings.set_Region(CountryCode value)
   at    . (    )
   at    . (    )
   at    .     (Stream )
   at    .(    , Stream )
   at    .(    , Stream )
   at   .(    , String )
   at   .()
   at   .(String , Stream , LoadOptions )
   at Aspose.Cells.Workbook.(Stream , LoadOptions , Boolean )
   at Aspose.Cells.Workbook..ctor(Stream stream)
   at TestProject.Controllers.HomeController.Index(IFormFile excelFile) in /app/Controllers/HomeController.cs:line 38
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

I’m using Version 20.9.0 with the following ASP.NET Core runtime:

/app # dotnet --list-runtimes
Microsoft.AspNetCore.App 3.1.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Dockerfile for building the image:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS sdk-image
WORKDIR /app/

RUN apt-get update \
    && apt-get upgrade -y \
    && apt-get -y install ca-certificates 
COPY certs /usr/local/share/ca-certificates/
RUN update-ca-certificates

# https://stackoverflow.com/questions/58184148/docker-with-dotnet-restore-causes-error-gssapi-operation-failed-an-unsupporte
RUN apt-get install -y gss-ntlmssp

COPY *.csproj .
RUN dotnet restore

COPY . .
RUN dotnet publish -c Debug -o /publish

FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine AS runtime-image
WORKDIR /app/
COPY --from=sdk-image /publish .

ENV CERT_PATH=/app/sign-cert.pfx
ENV CERT_PW=
ARG ASPNETCORE_ENVIRONMENT=Development
ENV ASPNETCORE_URLS=http://0.0.0.0:5000
ENV ASPNETCORE_ENVIRONMENT=${ASPNETCORE_ENVIRONMENT}
ENTRYPOINT ["dotnet", "TestProject.dll"]

Docker version on the workstation:

$ docker --version
Docker version 19.03.12, build 48a66213fe

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       foca

@Th3Dan,
We have tested and found that Asp.NetCore does not support some of the culture id, for example:

CultureInfo cl = new CultureInfo(1043 & 0xFFFF, true);

This code will return a “nl-NL” culture in .NetCore, but will get an error in Asp.NetCore.
To solve this problem we have provided a solution in Aspose.Cells 20.1 and greater versions.

//First, declare a class in your code:
class CustomImp : Aspose.Cells.CustomImplementationFactory {
public override System.Globalization.CultureInfo CreateCultureInfo(int lcid) {
try {
return new CultureInfo(lcid);
}
catch {
//You may modify this, implemment your culture here when exception occurs in asp.netcore
return CultureInfo.CurrentCulture;
}
}
}
//do the CustomImplementationFactory assignment before you open a workbook
Aspose.Cells.CellsHelper.CustomImplementationFactory = new CustomImp();

Please declare a class like this and do the CustomImplementationFactory assignment before you open a workbook. You may get latest version of Aspose.Cells from NuGet. Here is a sample project for your reference.
TestAsposeCellsInWebApi.zip (531.3 KB)