Hey, our app is set to globalization-invariant mode. I see we get CultureNotFoundExceptions because GroupDocs.Conversion requires cultures. Is there any way yo bypass this? Why are cultures needed in the conversion?
Thanks,
Dan
Hi Dan,
To bypass the CultureNotFoundException
in GroupDocs.Conversion while in globalization-invariant mode, you can set a default culture in your application. This is necessary because certain operations in the conversion process rely on culture-specific settings.
Here’s a straightforward approach you can take:
-
Set a Default Culture: Before performing any conversion, explicitly set the culture to a neutral one, such as
CultureInfo.InvariantCulture
. -
Example Code:
using System; using System.Globalization; using System.Threading; using GroupDocs.Conversion; class Program { static void Main() { // Set the culture to InvariantCulture Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture; try { var converter = new Converter("input.txt"); // Ensure the input file is a text file converter.Convert("output.pdf"); } catch (CultureNotFoundException ex) { Console.WriteLine("Culture not found: " + ex.Message); } catch (Exception ex) { Console.WriteLine("Conversion failed: " + ex.Message); } } }
By setting the culture to InvariantCulture
, you should be able to avoid the CultureNotFoundException
. Additionally, ensure that you handle other exceptions for a more robust solution.
If you continue to face issues, consider reviewing the GroupDocs.Conversion documentation for further troubleshooting tips.
Best regards!
Hello @dangilboa ,
Thanks for reporting this issue. To help our developers investigate the CultureNotFoundException
in globalization-invariant mode, could you please provide the following details?
- .NET version you are using (e.g., .NET 6, .NET 7, .NET 8).
- Operating system and environment (Windows, Linux distribution, Docker/Container image if applicable).
- How globalization-invariant mode is enabled in your setup (e.g.,
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
, runtimeconfig.json, etc.). - A stack trace of the CultureNotFoundException you receive.
- The version of GroupDocs.Conversion that you are using.
- A minimal code snippet that reproduces the issue in your environment.
With this information, our team will be able to better understand the context and suggest a proper solution or workaround.
Hey Evgen, here are the details,
-
.net 9.0
-
Docker Image
-
We dont enable any culture, that is why Globalization Invariant is enabled. It is the default
-
GroupDocs.Conversion.Exceptions.GroupDocsConversionException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'culture') 1033 (0x0409) is an invalid culture identifier. ---> System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See https://aka.ms/GlobalizationInvariantMode for more information. (Parameter 'culture') 1033 (0x0409) is an invalid culture identifier. at .(Exception , ConverterSettings , ) at .(CancellationToken ) at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of inner exception stack trace --- at ..(Exception ) at System.AggregateException.Handle(Func
2 predicate)
at .(CancellationToken )` -
We are using version 25.8.0
-
added image
image.png (37.2 KB)
Thank you very much,
Dan
Hello @dangilboa ,
Thank you for clarifying the details. Since you are using a Docker image, could you please let us know:
- Which .NET Docker image are you using?
- Do you have the
DOTNET_SYSTEM_GLOBALIZATION_INVARIANT
environment variable in your Dockerfile? - Are the ICU libraries (
icu-libs
orlibicu
) installed in the container?
If you could share your Dockerfile (or at least the relevant part where the .NET environment is configured), it would be very helpful.
Yes sure,
- Microsoft Artifact Registry
- no i dont have the DOTNET_SYSTEM_GLOBALIZATION_INVARIANT env var in my dockerfile
- The ICU libraries are not installed
None of the enviroment variables are related, but if it will still help let me know and i will send what i can
Thanks,
Dan
By default, Alpine images run .NET in globalization-invariant mode (DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1). In this mode only the invariant culture is supported, and any real culture identifiers (such as 1033 for en-US locale) are not recognized.
To fix this issue, you need to try installing ICU libraries in your container and disable invariant mode. For example, update your Dockerfile as follows:
FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine-amd64
RUN apk add --no-cache icu-libs icu-data-full
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
After this, .NET should be able to correctly handle globalization and culture-dependent data. If this does not resolve the issue, we will investigate it on our side. We look forward to your results.