Aspose.PDF aspose.pdf.24.1.0 > aspose.pdf.24.5.0 > The type initializer for 'Aspose.Pdf.XmpField' threw an exception

Line 3 throws “The type initializer for ‘Aspose.Pdf.XmpField’ threw an exception.” after upgrading from aspose.pdf.24.1.0 to aspose.pdf.24.5.0 (and also exists in aspose.pdf.24.5.1):

If I remove line 2, no exception is thrown.

1. var pdfDocument = new Aspose.Pdf.Document(pdf_doc_path);
2. pdfDocument.Info.Add("guid", guid.ToString());
3. pdfDocument.Save(pdf_doc_path);

References:
\Aspose\aspose.pdf.24.5.0.nupkg\lib\netstandard2.0\Aspose.PDF.dll
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.8\Facades\netstandard.dll
2024-05-17_07-04-49.png (18.6 KB)

Inner exception:
Could not load file or assembly ‘System.Text.Encoding.CodePages, Version—5.O.O.O, Culture—neutral, PublicKeyToken—b03f5f7f11d50a3a’ or one Of its dependencies. The system cannot find the file specified.

StackTrace
at Aspose.Pdf.XmpField.get_Empty()
at #=zOtLFjf0uc5I$NGL5b6e38tNb29E32DZUjtxxGFk=…ctor(#=z47TCYzSYQes2lyWP$j5w87ZxVTUMBcI5VnjxXcc= #=z9Cxx5hQ=, Boolean #=zAsTCS3TsxU$1)
at #=z69maIet4C$Ajhi5X5X1aSENo3AiepBXdaZws9Oo=…ctor()
at #=zuhZ3R2pmJ$XIuO$ZBmPaJp$HfDYrOT1Ue2MspBA=.#=z$mekk4Vj754o(Stream #=zkfE32z0=)
at #=zuhZ3R2pmJ$XIuO$ZBmPaJp$HfDYrOT1Ue2MspBA=…ctor(Stream #=zkfE32z0=)
at #=zTfFVCF2X5NTH8zs5VZ5GOGFxfCEMBgpjq7d4TTs=.#=zVOV2OM81KoWb()
at Aspose.Pdf.Document.get_Metadata()
at Aspose.Pdf.Document.get_IsPdfaCompliant()
at Aspose.Pdf.Document.#=zlgEE12d6Aliq(Stream #=zZt2EX98=, SaveOptions #=zL6PnXVoIov7G)
at Aspose.Pdf.Document.#=z9mRpoUfSiIRh(Stream #=zZt2EX98=, SaveOptions #=zL6PnXVoIov7G)
at Aspose.Pdf.Document.#=zTmo9H4xRMDm_(String #=zbxbHTPGxTzEE)
at Aspose.Pdf.Document.Save(String outputFileName)
at UserQuery.ProduceDocument(Int32 customerId, List1 locationsIds, List1 queriedSurveys, String system_instructions, String user_instructions, String ai_path_query_csv, String path_root, Language output_language, Double input_version, Double output_version)
at UserQuery.Main()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()

@mortenma

Can you please share the sample PDF for our reference as well? We will try to replicate the issue in our environment and address it accordingly.

Hi Asad. I have updated the original post with references and info that removing line 2 also removes the exception

@mortenma

Would you please try using Aspose.Pdf.Drawing 24.4 instead of Aspose.PDF for .NET? Also, please use NuGet Package Manager in order to install the API. We tested in our environment and could not replicate the issue:

var pdfDocument = new Aspose.Pdf.Document();
pdfDocument.Pages.Add();
pdfDocument.Info.Add("guid", new Guid().ToString());
pdfDocument.Save(dataDir + "output.pdf");

output.pdf (1.3 KB)