HTML to PDF Conversion issue throws System.InvalidOperationException using .NET

Unable to generate PDFs due to below issue, getting lots of escalations from customers. Please try to solve this problem asap as we have purchased Aspose.Total license.

2021-02-23T12:02:16.8848534+05:30 [ERR] Error Code: EIC-LI-UL | Error Message: Exception While Generating PDF from Method - GenerateInvoicePdfETL | Exception: System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection’s state is no longer correct.
at System.Collections.Generic.Dictionary2.FindEntry(TKey key) at System.Collections.Generic.Dictionary2.TryGetValue(TKey key, TValue& value)
at   .(Char )
at   .(Int32 )
at    . (   , Boolean )
at    .(String ,     , Boolean )
at Aspose.Words.Fields.FieldHyperlink.()
at    . ()
at    .     ( ​  )
at    .     ( ​  )
at    . ( ​  ,     )
at    .     ( ​  )
at    .     ( ​  )
at    .     ( ​  )
at  ​ . (    )
at  ​ . (    ,     )
at    .(    ,  ​  )
at    .     (    )
at    .     (    )
at Aspose.Words.Document.  (    )
at Aspose.Words.Document.​(Stream , String , SaveOptions )
at Bolton.EinvoiceEwayBill.Domain.FileManager.SaveInvoiceFile(Document document, Int32 OrganizationID, String year, String month, Boolean Force, String FileName, String SubModule, Boolean saveRecord) in /home/vsts/work/1/s/Bolton.EinvoiceEwayBill.Domain/FileManager.cs:line 646
at Bolton.EinvoiceEwayBill.Domain.GenerateEInvoiceDocumentServiceManager.GenerateInvoicePdfETL(Int32 organizationId, String outFileName, OutwardDocumentHeaderViewModel OutwardDocumentHeaderDetails, List1 lineItemDetails, List1 ewaybillDocumentDetails, EinvoiceIrnDetails einvoiceIrnDetails, EnumerableRowCollection`1 templateInfo, Int32 outwardDocumentHeaderID, Int32 irnId) in /home/vsts/work/1/s/Bolton.EinvoiceEwayBill.Domain/GenerateEInvoiceDocumentServiceManager.cs:line 326 (018efa8c)

@VenkateshBT

Aspose.Words does support multi-threading. The only thing you need to make sure is that always use separate Document instance per each thread. One thread should use one Document object (one single template).

If you still face problem, please ZIP and attach your input documents along with sample code example to reproduce this issue at our end. We will investigate the issue and provide you more information on it.

HI Tahir,

As per your suggestion i have created new document object and used. But still similar issue as below:

Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: Error Code: EIC-LI-UL | Error Message: Exception While Generating DOC | Exception: System.NullReferenceException: Object reference not set to an instance of an object.
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: at System.Collections.Generic.Dictionary2.set_Item(TKey key, TValue value)
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [20B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [21B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [21B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [34B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [64B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [47B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [64B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [57B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [33B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [17B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [33B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [27B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [27B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [32B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [32B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [32B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [32B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [46B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [41B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [41B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [41B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [41B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [52B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [32B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [46B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [63B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [32B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [20B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [17B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: at Aspose.Words.Document.UpdatePageLayout()
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [33B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [29B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [46B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [40B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: [26B blob data]
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: at Aspose.Words.Range.UpdateFields()
Mar 09 23:51:14 DTTB2AP2 dotnet[21118]: at Aspose.Words.Document.UpdateFields()

Can you please help to resolve the issue.

@VenkateshBT,

Please upgrade to the latest (21.3) version of Aspose.Words for .NET and see how it goes on your end? In case the problem still remains, then please provide a standalone simple Console application (source code without compilation errors) along with source document that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size. We will then start further investigation into your issue and provide you more information.