Exception"Null reference" when converting PDF to HTML(C#)

When using multiple threads to convert PDFs to other formats (have tested this with Word and HTML), I sporadically get a null reference error:
Error processing C:\Users\steven\Desktop\Demo Results\Processed\Alfreds Futterkiste.pdf: System.NullReferenceException: Object reference not set to an instance of an object.
at System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) at #=z7B66NTNGFA169JLoUmrwKxgD8jaW.#=zrehnqg4=() at #=zjQofK5uQT1nrczm2hqUfn5rTB69qRYYos7w$enU=.#=zc07YwmE=(IList1 #=zXQV4p3t6b6Zw, #=zUXsHvDp_PywOqaOUR5YzYceSxILpMOyVPA== #=zdBORxco=, #=zhEH9Bc_Wang_9YLQVBUdfsZatAgmzuy2AOpUOpg= #=zds9OORg=)
at #=zSkKpsnW4_l8d3oWw$rCKZvnjq_0o.#=zc07YwmE=(String #=zJaRRVAGKJ0$y, #=zhOwO0qGv1_zr7ukGF8zdWlJryxnLBgmyZw== #=zds9OORg=, IList`1 #=zXQV4p3t6b6Zw, #=zElZS3rTNPGRb2G8bbB096HjlemU26jn78oFyxoU= #=z1Un$IH4=, #=zoJ0W652CgKjIWtgorYMNb57mwf5e #=zDppDFBU8JVcJ)
at #=zMYqbptfeeqhc6FkgO9qM6Ug=.#=zB9de9gE=(Document #=zgdQy3nA=, String #=zx6UtPYJ33E_xuAIJOw==, Stream #=z2fSaFZn_yKhE, HtmlSaveOptions #=zds9OORg=)
at Aspose.Pdf.Document.#=zEszYJEKR61hZ(String #=zJaRRVAGKJ0$y, SaveOptions #=zds9OORg=)
at Aspose.Pdf.Document.Save(String outputFileName, SaveOptions options)
at All_About_PDF.PDFConverter.convertPDFToHTML(String file, String outputFolder, String password, Boolean zipResult) in PDFConverter.cs:line 257
at All_About_PDF.PDFConverter.<>c__DisplayClass3_0.b__0(String file) in PDFConverter.cs:line 99

This occurs when I put the conversion in Parallel.ForEach with 4 threads.

@amani7,

Thanks for contacting support.

Can you please share source files along with sample code so that we may further investigate to help you out.

    static string convertPDFToWord(string file, string outputFolder, string password = "")
    {
        string outputFile = System.IO.Path.Combine(outputFolder, System.IO.Path.GetFileNameWithoutExtension(file) + ".docx");

        using (Aspose.Pdf.Document doc = new Aspose.Pdf.Document(file, password))
        {
            Aspose.Pdf.DocSaveOptions saveOptions = new Aspose.Pdf.DocSaveOptions();
            saveOptions.Mode = Aspose.Pdf.DocSaveOptions.RecognitionMode.Flow;
            saveOptions.Format = Aspose.Pdf.DocSaveOptions.DocFormat.DocX;

            doc.Save(outputFile, saveOptions);
        }

        return outputFile;
    }

    static void Convert(List<string> ValidFiles, string format)
    {

        var ThreadOptions = new ParallelOptions() { MaxDegreeOfParallelism = 1 };// errors occur when set to more than 1
        var outputFolder = System.IO.Path.GetTempPath();

        Parallel.ForEach(ValidFiles, ThreadOptions, (file) =>
        {

            string password = "";

            try
            {
                switch (format)
                {

                    case "msword":
                        var resultFile = convertPDFToWord(file, outputFolder, password);
                        break;
                        //case FORMAT_ENUM.POWERPOINT:
                        //    resultFile = convertPDFToPowerPoint(file, outputFolder, password);
                        //    break;
                        //case FORMAT_ENUM.MSEXCEL:
                        //    resultFile = convertPDFToExcel(file, outputFolder, password);
                        //    break;
                        //case FORMAT_ENUM.PNG:
                        //    resultFile = convertPDFToJpg(file, outputFolder, password);
                        //    break;
                        //case FORMAT_ENUM.EPUB:
                        //    resultFile = convertPDFToEpub(file, outputFolder, password, useZip);
                        //    break;
                        //case FORMAT_ENUM.TEXT:
                        //    resultFile = convertPDFToText(file, outputFolder, password);
                        //    break;
                }
            }
            catch (Exception fileEx)
            {
                throw fileEx;
            }

        });
        }

Around the Horn.pdf (337.8 KB)

To reproduce the issue, make 100 copies of the attached PDF and pass them into the ValidFiles list. Set the MaxDegreeOfParallelism to 4.

@amani7,

Thank you for contacting support.

Can you please share complete environment details and version details to further investigate this issue on our end.

Running on Windows 10, Visual Studio 2017 and Aspose.PDF version 20.3.0.0. Application is running on .NET 4.6.1 targeting AnyCPU.

@amani7,

Thanks for contacting support.

I have observed your issue and like to inform that I have created investigation ticket with ID PDFNET-48334 in our issue tracking system to investigate and resolve this issue as soon possible.