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();
}
}