Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Feb 02, 2015 3:49 am

Hi, when using Free Spire.PDF to convert PDF to XPS it appears the SaveToStream & SaveToFile operations are not threadsafe.

There is a race-condition that may result in errors such as "Item has already been added. Key in dictionary" and "Object reference not set to an instance of an object" despite each thread creating it's own instance of PdfDocument.

Please advise if you are aware and if a fix will be provided.

Example code (run several times to re-create):

void Main()
{
var pdfFile1 = @"C:\Temp\1.pdf";
var pdfFile2 = @"C:\Temp\2.pdf";
var pdfFile3 = @"C:\Temp\3.pdf";

ThreadPool.QueueUserWorkItem(s => Convert(pdfFile1));
ThreadPool.QueueUserWorkItem(s => Convert(pdfFile2));
ThreadPool.QueueUserWorkItem(s => Convert(pdfFile3));
}

public void Convert(string pdfFile)
{
var pdfDoc = new PdfDocument();
try
{
pdfDoc.LoadFromFile(pdfFile);
pdfDoc.SaveToStream(new MemoryStream(), FileFormat.XPS);
}
finally
{
pdfDoc.Close();
pdfDoc.Dispose();
}
}

pienaarp
 
Posts: 1
Joined: Tue Dec 30, 2014 8:13 am

Mon Feb 02, 2015 8:14 am

Hello pienaarp,

Thanks for your inquiry.

To help us reproduce this problem, can you provide us your testing pdf documents? Thank you.
Best Regards,
Burning
E-iceblue Support Team
User avatar

burning.liu
 
Posts: 406
Joined: Mon Aug 04, 2014 6:47 am

Return to Spire.PDF

cron