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

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

@Sukhvinder
What version of the library are you using?
If Aspose.Pdf, then try Aspose.Pdf.Drawing instead.

@sergei.shibanov Currently we are using Aspose.PDF 23 as per attached sectionasposeversion.PNG (30.9 KB)

Can you please let us know which version we can use as We need to purchase license ,Which product we can buy license Aspose.PDF or Aspose.PDF.Drawing ?Please confirm.

@Sukhvinder
Both libraries work with the same license. When buying, it is better to clarify (specify) it. But technically now so. Aspose.Pdf.Drawing is better for working in Linux systems.

@sergei.shibanov Thanks you, As per your suggestion now culture not found error resolved but now it is failing when we are saving the document and throwing below error
Throwing error on this line - pdfDocument.Save(streamsd, Aspose.Pdf.SaveFormat.Pptx);

Do you have any idea how can we save ppt and return as byte when i am skipping above line then it is returning empty.
Stack Trace

RenderPptxTemplateAsync Document exception: System.IO.IOException: Read-only file system : ‘/tmp/TempFonts’
at System.IO.FileSystem.CreateDirectory(String fullPath)
at #=z74Fq7n$Gl64wbpnfW9MesDaMR9voN28ahQ==.#=zauMb4Wt5DjmD()
at #=z74Fq7n$Gl64wbpnfW9MesDaMR9voN28ahQ==…ctor()
at #=zxcMJNWhEaXXFJp7zsNrx15gu0CFU.#=zfy1V6mc=(String #=zO$fm2lM=, #=zmYkWHgSPEk2G2YygMTYBqkFypBYV #=zg$b4LR4=)
at #=zbS5D3o0o95iypdB$Sd_RNv73aPM2cad4gw==.#=zL0G6SvejW79X(#=zmYkWHgSPEk2G2YygMTYBqkFypBYV #=zg$b4LR4=)
at #=zbS5D3o0o95iypdB$Sd_RNv73aPM2cad4gw==.#=zT$GNo1WPuBg1y7CvSg==(#=zmYkWHgSPEk2G2YygMTYBqkFypBYV #=zg$b4LR4=)
at #=zRGUKcHGury$zDrZudw0JoCKJGSc3dqDGtdpTNV4=.#=ziAVWnZJq9dJyFfNtdJioreLNbINK(#=za0VtmMCe35HuTO$qKIMglsst$1PyshXlQg== #=zbT5$1akeHUx1, #=za0VtmMCe35HuTO$qKIMglsst$1PyshXlQg== #=zi_oVOYlNRmHg)
at #=zRGUKcHGury$zDrZudw0JoCKJGSc3dqDGtdpTNV4=.#=z9X8Ojh6OWax1(#=zrgCSNDnanlcpyvy2fYquewv3apzU #=zvd0uFOc=, Boolean #=zIjiqPnLA16SOSueI0Q==, Boolean #=z8Fuf$yo=)
at #=zRGUKcHGury$zDrZudw0JoCKJGSc3dqDGtdpTNV4=.#=zU2xcXhc=(#=zrgCSNDnanlcpyvy2fYquewv3apzU #=zvd0uFOc=, Boolean #=zIjiqPnLA16SOSueI0Q==)
at #=ztfC1n7uu8ojclO2l0Z9dwIb2vP9AbxA6lw==…ctor(#=zscRVqV1NAej$IF4yFwAStwmnTjrb #=zcqg9ZFM=, #=zK$fBLfaTUno2VAB6Enl7Ck24XJHmXpY$OpZxCSY= #=z9BlIXgs=, List1 #=zXpTsEDg=, List1 #=z04dzXjo=, Boolean #=zUz6EL88j_6yAXKVvWK2m60$uEUB4o27EXg==, Boolean #=ziKukhXusCfdCVN2EWw==)
at #=zKp42sDdBCeeEYwrDGY1KZ_wsvR$8s7NKxw==.#=zzqBFrS_KCTkUf2$fAA==(#=zw1PiL7Ahw0xEELEsb_2JzaU= #=z3McrTS8=, Single #=zK5IEPKvdSpRZ, Single #=zVGlfhIKQ2Dom, #=zK$fBLfaTUno2VAB6Enl7Ck24XJHmXpY$OpZxCSY= #=z9BlIXgs=, Boolean #=zUz6EL88j_6yAXKVvWK2m60$uEUB4o27EXg==, Boolean #=ziKukhXusCfdCVN2EWw==, #=zKp42sDdBCeeEYwrDGY1KZ_wsvR$8s7NKxw== #=ze6VFiEc=)
at #=zKp42sDdBCeeEYwrDGY1KZ_wsvR$8s7NKxw==.#=zzqBFrS_KCTkUf2$fAA==(#=zw1PiL7Ahw0xEELEsb_2JzaU= #=z3McrTS8=, Single #=zK5IEPKvdSpRZ, Single #=zVGlfhIKQ2Dom, #=zKp42sDdBCeeEYwrDGY1KZ_wsvR$8s7NKxw== #=ze6VFiEc=)
at #=zKp42sDdBCeeEYwrDGY1KZ_wsvR$8s7NKxw==.#=z_M185yN6winK6Wa1Bx$Pjss=(#=zw1PiL7Ahw0xEELEsb_2JzaU= #=z3McrTS8=, SizeF #=zEW0qqSo=)
at #=z4c2bNQ96jlP0zE9dMfUiwnUn4fMi$q5N0mYitbY=.#=zINuimrg=(IList1 #=zd04maSBOsEoG, #=zisxCjYoVfthZiHZKKmyWE9KSU2J3jzrsiA== #=zqCRAJ2c=, #=zt$$TpbTPIW2LOxlYHFfW$VkLPL7U7RDjwnA$mcs= #=zC8H9DY8=) at #=zM6R78iELVOUwC6I6Z605bGSV4f6w.#=z0v4AuMbh2MPwA3X_Ag==(List1 #=zbV1UD50=)
at #=zgWwdw$lh_npc4NQkVOD7C6l_wciiE1FMBA==.#=z2chjyOQrOBHt(List`1 #=zd04maSBOsEoG, Stream #=zhGZCK3QA$7Vf, PptxSaveOptions #=zC8H9DY8=)
at #=zgWwdw$lh_npc4NQkVOD7C6l_wciiE1FMBA==.#=zINuimrg=(Document #=zHVmFA6o=, Stream #=zhGZCK3QA$7Vf, PptxSaveOptions #=zC8H9DY8=)
at Aspose.Pdf.Document.#=zEoWK9eIwWhSp(Stream #=z8WYr_7pbgzEv, SaveOptions #=zC8H9DY8=)
at Aspose.Pdf.Document.#=zEoWK9eIwWhSp(Stream #=z8WYr_7pbgzEv, SaveFormat #=zjMZpFjo=)
at Aspose.Pdf.Document.Save(Stream outputStream, SaveFormat format)
at CI.DataAggregation.Services.PdfExport.PdfTemplateLoader.RenderPptxTemplateAsync(String template) in /src/services/CI.DataAggregation/Services/PdfExport/PdfTemplateLoader.cs:line 159