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.