Aspose.PDF Running .NET 6 project in Docker throws Globalization.CultureNotFoundException after deployment on linux

Hello Aspose Team,

I have updated .NET 6 API project with Aspose.pdf, It is working fine on local system and ppt is generating successfully But When same deploying on docker server, It is throwing error System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode.
en-US is an invalid culture identifier.
After checking converted ppt file via your methods works fine on window system and online after deployed on AKS docker container it does not work.

Please help to solve this issue ASAP.
Sukhvinder Singh

@Sukhvinder
I think the answers on these pages (where the same question is asked) will help you.

@sergei.shivanov I have already tried Running .NET 6 project in Docker throws Globalization.CultureNotFoundException - Microsoft Q&A provided link but in my case it did not worked, Can you please provided alternate solution for the same and can we have quick call on teams.

@Sukhvinder
As I understand it, if not in docker, it works for you, if you run the application in a docker container (under Linux), an error occurs?
Can you provide the code snippet and dockerfile you are using to reproduce the issue and challenge the developers if needed?

Hi Sergei Shibanov,

PFA Report Summary html template string which I am using for convert into pptx and Docker file to upload on docker container along with code snippet file.

Best Regards,
Sukhvinder Singh

(Attachment ReportsSummarypptx.html is missing)

(Attachment Dockerfile is missing)

(Attachment codesnippet.txt is missing)

Hi Sergei Shibanov,

PFA Report Summary html template string which I am using for convert into pptx and Docker file to upload on docker container along with code snippet file- as zip file.

Best Regards,
Sukhvinder Singh

asposedocs.zip (322 KB)

@Sukhvinder
For some reason, the attached files are not shown (at least for me). Please attach them again.

Hi Sergei Shibanov,

PFA Report Summary html template string which I am using for convert into pptx and Docker file to upload on docker container along with code snippet file- as zip file.

Best Regards,
Sukhvinder Singhasposedocs.zip (321.5 KB)

@Sukhvinder
I can not build and run the code with the given data. Let me ask you a few questions:

  • Is it possible use only first two lines for reproduce issue?
HtmlLoadOptions options = new HtmlLoadOptions();
var pdfDocument = new Aspose.Pdf.Document(htmlString, options);

q1.png (31.1 KB)

  • htmlString - name of the file to be converted (“ReportsSummarypptx.html”) or something else?

  • If all code must used please explain what the environment shows as errors (in the screenshot it is shown underlined by the environment). _logger I can remove, and what about else.
    q2.png (36.7 KB)

  • What type of project is used - is it possible to reproduce this in a console application for .Net 6?

Hi Sergei Shibanov,

PFB my answer of your queries.

  • Is it possible use only first two lines for reproduce issue?

Answer- Yes

Answer - htmlString as read html from file as string and pass it, which I have shared.

HtmlLoadOptions options = new HtmlLoadOptions();

var pdfDocument = new Aspose.Pdf.Document(htmlString, options);

Answer - Above Line is throwing error after deploying on aks docker container

htmlString - name of the file to be converted (“ReportsSummarypptx.html”) or something else?

Answer - Yes **htmlString is html which is read form** (“ReportsSummarypptx.html”) file

If all code must used please explain what the environment shows as errors (in the screenshot it is shown underlined by the environment). _logger I can remove, and what about else.
Answer - Yes You can remove _looger it is being used for log the event only and you can remove underlined error and other error you can remove and the environment is kubernates docker container pods.

· What type of project is used - is it possible to reproduce this in a console application for .Net 6?

Answer - I am using Web Api project with Net 6 core and I am not sure console application will work on aks environment.

The below code is working fine on my local machine-

static readonly string textFile = @ “C:\Temp\Data\ ReportsSummarypptx.html”;

public static void ConvertHTMLtoPPTX()

{

if (File.Exists(textFile)) {

// Read entire text file content in one string

string text = File.ReadAllText(textFile);

// load HTML with an instance of Document

var document = new Document(text, new HtmlLoadOptions());

// save document in PPTX format

document.Save(“output.pptx”, Aspose.Pdf.SaveFormat.Pptx);

}

}

Best Regards,

Sukhvinder Singh

@sergei.shibanov

PFB my answer of your queries.
• Is it possible use only first two lines for reproduce issue?
**Answer- Yes **
Answer - htmlString as read html from file as string and pass it, which I have shared.
HtmlLoadOptions options = new HtmlLoadOptions();
var pdfDocument = new Aspose.Pdf.Document(htmlString, options);
Answer - Above Line is throwing error after deploying on aks docker container

htmlString - name of the file to be converted (“ReportsSummarypptx.html”) or something else?
Answer - Yes htmlString is html which is read form (“ReportsSummarypptx.html”) file

If all code must used please explain what the environment shows as errors (in the screenshot it is shown underlined by the environment). _logger I can remove, and what about else.
Answer - Yes You can remove _looger it is being used for log the event only and you can remove underlined error and other error you can remove and the environment is kubernates docker container pods.

• What type of project is used - is it possible to reproduce this in a console application for .Net 6?
Answer - I am using Web Api project with Net 6 core and I am not sure console application will work on aks environment.
The below code is working fine on my local machine-
static readonly string textFile = @ “C:\Temp\Data\ ReportsSummarypptx.html”;
public static void ConvertHTMLtoPPTX()
{
if (File.Exists(textFile)) {
// Read entire text file content in one string
string text = File.ReadAllText(textFile);
// load HTML with an instance of Document
var document = new Document(text, new HtmlLoadOptions());
// save document in PPTX format
document.Save(“output.pptx”, Aspose.Pdf.SaveFormat.Pptx);
}
}

This code doesn’t work for me, and according to the specification, it should be the filename, not the content.
1.png (19.3 KB)

HI @sergei.shibanov
I am using below code snippet for ppt , It is working fine for me on local, attached snapshot for same.
If still you are not able to run the code , Can we have screen sharing session from your side on sukhvinder_singh@edwards.com, you can send me meeting invite for the same
docppt.PNG (71.4 KB)

 public async void RenderPptxTemplateAsync(string template)
       {
           try
           {
               //string template as html string read from template 
               var stream = new MemoryStream(Encoding.UTF8.GetBytes(template));
               HtmlLoadOptions options = new HtmlLoadOptions();
               // Set render to single page property
               Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream, options);
               // Create page number stamp
               PageNumberStamp pageNumberStamp = new PageNumberStamp();
               // Whether the stamp is background
               pageNumberStamp.Background = false;
               pageNumberStamp.Format = "Page # of " + pdfDocument.Pages.Count;
               pageNumberStamp.BottomMargin = 36;
               pageNumberStamp.HorizontalAlignment = HorizontalAlignment.Center;
               pageNumberStamp.StartingNumber = 1;
               // Set text properties
               pageNumberStamp.TextState.Font = FontRepository.FindFont("Arial");
               pageNumberStamp.TextState.FontSize = 14.0F;
               pageNumberStamp.TextState.FontStyle = FontStyles.Bold;
               pageNumberStamp.TextState.FontStyle = FontStyles.Regular;
               pageNumberStamp.TextState.ForegroundColor = Color.Gray;
               // Add stamp to particular page
               for (int i = 1; i < pdfDocument.Pages.Count; i++)
               {
                   if (pdfDocument.Pages.Count != i && i != 1)
                   {
                        if (pdfDocument.Pages.Count - 1 != i)
                       {
                           pdfDocument.Pages[i].AddStamp(pageNumberStamp);
                       }
                   }
               }
               pdfDocument.Save("output.pptx", Aspose.Pdf.SaveFormat.Pptx);
             

           }
           catch (Exception ex)
           {
           
           }

@Sukhvinder
Thank you for clarifying. I finally understanding that when creating a document, a stream (not a string) is given into which the contents of the file being opened are loaded.
I created a Web Api application (“from the box”) and added the above method there and modified the dockerfile created by the visial studio to match the one you attached. Except for the paths, but I think it doesn’t matter.
However, I haven’t been able to reproduce the exception yet.
Tomorrow I will continue to work on this and write to you.
Although I think it works here that I run the docker from the Visual Studio. It is possible that when you start, there are some peculiarities of your own, there is a locally necessary culture, but not in Azure.

@sergei.shibanov It is working in debug mode our side also, However when we are deploying on aks docker container same method not working and throwing below error on this line Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream, options);
objecterror.png (105.2 KB)

@Sukhvinder
Please attach stacktrace as a text.objecterror.png (105.9 KB)

@sergei.shibanov

PFA stack trace for the same
RenderPptxTemplateAsync Document exception: System.Exception: The type initializer for ‘#=znt5o9XIt7lRZOwQjcxv8X8g63Bw6kmo5wQ==’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘#=znt5o9XIt7lRZOwQjcxv8X8g63Bw6kmo5wQ==’ threw an exception.
—> System.TypeInitializationException: The type initializer for ‘#=ziNiGDyXjY3Ypa8OJZN3njZh2gscL’ threw an exception.
—> System.Globalization.CultureNotFoundException: Only the invariant culture is supported in globalization-invariant mode. See Globalization config settings - .NET | Microsoft Learn for more information. (Parameter ‘name’)
en-US is an invalid culture identifier.
at System.Globalization.CultureInfo…ctor(String name, Boolean useUserOverride)
at System.Globalization.CultureInfo…ctor(String name)
at #=ziNiGDyXjY3Ypa8OJZN3njZh2gscL…cctor()
— End of inner exception stack trace —
at #=znt5o9XIt7lRZOwQjcxv8X8g63Bw6kmo5wQ==…cctor()
— End of inner exception stack trace —
at #=znt5o9XIt7lRZOwQjcxv8X8g63Bw6kmo5wQ==.#=zcu5TFvlFnUGW()
at #=znt5o9XIt7lRZOwQjcxv8X8g63Bw6kmo5wQ==…ctor(#=z410ewA8_XxxVObJqO3aKTBo= #=za9q6HOo=, #=zt1nanRAOsonsVmLSKEweg5P1viWf #=zAtqEnjk=)
at #=zdyeNcYBl8SVKJ87CMy2q_bmBs_D2uuGvSA==.#=z2kwRJ7g=(#=z410ewA8_XxxVObJqO3aKTBo= #=za9q6HOo=, #=zt1nanRAOsonsVmLSKEweg5P1viWf #=zAtqEnjk=)
at #=z410ewA8_XxxVObJqO3aKTBo=.#=z2KV_7jnasYtE.#=zIs_TOoJDdiClI0aV0g==.#=z_ZpAFx_A4o2M01rXUw==()
at #=zwqbe$hjfo6kl$$LhEyUntfU=.#=zYVV0NyY=()
— End of inner exception stack trace —
at #=ziL4NRqm57bNDxY2Ik0G30sGsQYg9.#=znoi8KMY=(Boolean #=z2rwptz0=)
at #=zsXwYCo8lDR2aqKE9o0AQk1Qkx30X.Dispose()
at #=z410ewA8_XxxVObJqO3aKTBo=.#=z5xXPuSo=(#=z7fCVjwkgXVMe #=zVEq2fe4=)
at #=zkcipR3IcqEHu9YdpF$tYrzc=…ctor(#=zVwQTuKAkxWwhnsTwPhplk3xWALUl #=zOIOW9F4=, #=zF_DuspoAZ32$A4tzTz5DA3c= #=zAtqEnjk=, Byte #=zVARJd34=)
at #=zkcipR3IcqEHu9YdpF$tYrzc=…ctor(Stream #=znp8FP8I=, String #=zQXffoAI=, #=zF_DuspoAZ32$A4tzTz5DA3c= #=zAtqEnjk=)
at #=zu1jMUMh7CEeJYwLfOeDaNzqODzCE.#=z_vBY2rX8kAGM(Stream #=zkCd_wMCrVgXE, Document #=zTCsZqG65l6Qv, HtmlLoadOptions #=zeyK3uNu2RdwB, String #=zbL0C9cAY1Tof)
at #=zu1jMUMh7CEeJYwLfOeDaNzqODzCE.#=zs2R79CU=(Stream #=zkCd_wMCrVgXE, Document #=zTCsZqG65l6Qv, HtmlLoadOptions #=zeyK3uNu2RdwB, String #=zbL0C9cAY1Tof)
at #=zu1jMUMh7CEeJYwLfOeDaNzqODzCE.#=zs2R79CU=(Stream #=zkCd_wMCrVgXE, Document #=zTCsZqG65l6Qv, HtmlLoadOptions #=zeyK3uNu2RdwB)
at Aspose.Pdf.Document.#=zsTaJcuo=(Stream #=zOL$RYgQ=, LoadOptions #=zLAt2_$U=)
at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)
at CI.DataAggregation.Services.PdfExport.PdfTemplateLoader.RenderPptxTemplateAsync(String template) in /src/services/CI.DataAggregation/Services/PdfExport/PdfTemplateLoader.cs:line 132

@Sukhvinder
I don’t have access to Azure, I only added Docker Compose and I couldn’t reproduce the exception. But thanks to the presented stack trace, the possible reason understanding and I can set the task for the development team.
From what I’ve learned (first of all Globalization config settings - .NET | Microsoft Learn) I think you should set the following variables:
InvariantGlobalization to false (not sure here, you can try with true)
PredefinedCulturesOnly to false
and add setting variables primarily to the project file

   <PropertyGroup>
     <InvariantGlobalization>false</InvariantGlobalization>
     <PredefinedCulturesOnly>false</PredefinedCulturesOnly>
   </PropertyGroup>

(and at first it’s better to docker file too).

@Sukhvinder
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): HTMLNET-4438

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@sergei.shibanov After making suggested changes above getting below error - Stack traces
RenderPptxTemplateAsync Document exception: System.PlatformNotSupportedException: System.Drawing.Common is not supported on this platform.
at System.Drawing.Drawing2D.Matrix…ctor(Single m11, Single m12, Single m21, Single m22, Single dx, Single dy)
at #=z5r4vZ7kcB$xtlbZmR5oe5OLYfnzrubYIOA==.#=zYiJfTC4UD3i0uLEoP0efjy8=(SizeF #=zYPfCAnU=)
at #=z5r4vZ7kcB$xtlbZmR5oe5OLYfnzrubYIOA==.#=zEjIcVgQ=(SizeF #=zYPfCAnU=)
at #=zkkCiwiWtU7H2KphWx_VA29Ik2FZq_c3ScA==.Render(#=zAekiust3wvApDkMClJJOYvF8qKGS #=zayd1ksI=, CancellationToken #=z$Cj3hNs=)
at #=zZNs7jACDMPUriDpkiU0MA9Hn4NT_M$APxQ==.#=zKS$fonEz0I7_(#=zap_Ujgf3yJ1bo7KjPqC_Xd8= #=zuRs8sXEHxAzpoGSFYg==, #=zkGGXSQvtJ9KQJ0jnLD8DKWzMCJMR[] #=zp8uwJ4TtkQY8, #=zAekiust3wvApDkMClJJOYvF8qKGS #=zayd1ksI=, CancellationToken #=z2u3N_Vg=)
at #=zlKIjKOpqmX_BvdiX8bMmeDiQV6CE.Render(#=zAekiust3wvApDkMClJJOYvF8qKGS #=zayd1ksI=, CancellationToken #=z2u3N_Vg=, #=z2Xb90SDflNKcgCkElFJaigI=[] #=zsqHrZhg=, #=z410ewA8_XxxVObJqO3aKTBo=[] #=zdpUahS8=)
at #=zlKIjKOpqmX_BvdiX8bMmeDiQV6CE.Render(#=zAekiust3wvApDkMClJJOYvF8qKGS #=zayd1ksI=, TimeSpan #=zBX_kAxo=, #=z410ewA8_XxxVObJqO3aKTBo=[] #=zdpUahS8=)
at #=zwD0lwO3vq8jisH7_mnj9ywslxeIG.Render(#=zAekiust3wvApDkMClJJOYvF8qKGS #=zayd1ksI=, #=z$8t$NHA= #=za9q6HOo=, TimeSpan #=zBX_kAxo=)
at #=zu1jMUMh7CEeJYwLfOeDaNzqODzCE.#=z_vBY2rX8kAGM(Stream #=zkCd_wMCrVgXE, Document #=zTCsZqG65l6Qv, HtmlLoadOptions #=zeyK3uNu2RdwB, String #=zbL0C9cAY1Tof)
at #=zu1jMUMh7CEeJYwLfOeDaNzqODzCE.#=zs2R79CU=(Stream #=zkCd_wMCrVgXE, Document #=zTCsZqG65l6Qv, HtmlLoadOptions #=zeyK3uNu2RdwB, String #=zbL0C9cAY1Tof)
at #=zu1jMUMh7CEeJYwLfOeDaNzqODzCE.#=zs2R79CU=(Stream #=zkCd_wMCrVgXE, Document #=zTCsZqG65l6Qv, HtmlLoadOptions #=zeyK3uNu2RdwB)
at Aspose.Pdf.Document.#=zsTaJcuo=(Stream #=zOL$RYgQ=, LoadOptions #=zLAt2_$U=)
at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)
at CI.DataAggregation.Services.PdfExport.PdfTemplateLoader.RenderPptxTemplateAsync(String template) in /src/services/CI.DataAggregation/Services/PdfExport/PdfTemplateLoader.cs:line 132