We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert XSL-FO to PDF in multi-threaded environment - NullReferenceException Occurs

When we try to create a new XSL-FO Document (with XslFoLoadOptions) from different threads (50-100 threads with different documents and files) we got a NullReferenceException.

If we use a Lock and Document creates one by one everything starts to work, but it’s critical for us to use this functionality in parallel.
Please help us.

This code is not working

        Document docPDF = new Document(stmpFO, new XslFoLoadOptions());
        docPDF.Save(soutPDF);

This is working but cannot be acceptable

    lock (mAsposeLockObject)
    {
        Document docPDF = new Document(stmpFO, new XslFoLoadOptions());
        docPDF.Save(soutPDF);
    }

Exception

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Aspose.PDF
StackTrace:
at #=zOIOHnsX8T48qph__mAZcYFSlIHrXdGzK9A==.#=zpXEY5uXEx8moYjxhXg==(Exception #=zx3Q0OWg=, #=zfcZieRuPDxPwGpJc85s3uYw= #=zpltJkX8lTSMf)
at #=zOIOHnsX8T48qph__mAZcYFSlIHrXdGzK9A==.#=zcQYJdOo=(Document #=zXmePghg=, Stream #=zykx95oSKBxzz, XslFoLoadOptions #=zE7K0jDCLvNUe)
at Aspose.Pdf.Document.#=zSqLNJOo=(Stream #=zBvqVpu0=, LoadOptions #=zv$hB9d8=)
at Aspose.Pdf.Document…ctor(Stream input, LoadOptions options)
at XMLtoXSLFO.Program.GeneratePDF(Int32 nProcess, String sXSLPath, String sXMLPath, String sFOPath) in XMLtoXSLFO\XMLtoXSLFO\Program.cs:line 90

@victorak

Would you kindly confirm if you are using latest version of the API. In case you are facing same issue with latest version, would you kindly share a sample console application which is able to replicate the issue in our environment. We will test the scenario in our environment and address it accordingly.

Hello @asad.ali
We are using the latest version 19.12.0 from NuGet (December 05, 2019).
Please check attached archive with a test application, please just run it several times and will be stabile exception.
XSLFO-PDF.zip (6.9 KB)
To start application will install with Nuget Aspose.PDF for .Net.

@victorak,

Thanks for contacting support.

We have worked with source file and sample code shared by you using Aspose.PDF latest version in our environment and unable to observe the issue. We have also shared generated result with you for your kind reference. Please check attachment.Generated Result.zip (839.9 KB)

@Adnan.Ahmad

Thanks for respond and try.

Yes, some time is working, in debug mode it works 2-3 times from 10 starts, in release 1 time from 10 starts. This is why I ask you to run the test application several times.
Seems like it depends on thread racing, and this is why it working sometimes.

Please just try to run test application 4-5-6 times and you will reproduce an exception.

We really need well-working functionality with thread parallel processing PDF documents and as it will be fixed and we will be sure everything is working strong we immediately buy this product.

@victorak,

Thanks for contacting support.

We have tested this scenario in our environment and have been able to observe the issue that you have mentioned. We have logged issue with ID PDFNET-47479 in our issue tracking system. We will share with you as soon as logged issue is fixed.

Nice to see that you manage to reproduce it. We are waiting for your feedback.

Thanks,

@ar0026

Sure, we will inform you as soon as we have some updates in this regard.