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

Free Support Forum - aspose.com

contextSwitchDeadlock when replacing in large PDF file


I’m working on a C# .NET project using Aspose.Pdf.Text which has a function to replace some tags in a PDF file.
I’m using Aspose.Pdf_11.3.0 and .Net Framework 4.5.2.

When I run the following code, I always get a contextSwitchDeadlock exception raised in Visual Studio 2015 (Community Edition) .

public static int SearchReplace(List<KeyValuePair<string, string>> tags, string filePath)
int result = 0;

Document pdfDocument = new Document(filePath);

foreach (KeyValuePair<string, string> kvp in tags)
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(kvp.Key);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;

//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
string str = textFragment.Text;

textFragment.Text = str.Replace(kvp.Key, kvp.Value);

// Save resulting PDF document.

return result;

catch (Exception ex)
throw ex;

The tags collection contains over 3K items and the PDF is about 94ko.

The exception is often raised after hundred loops or more.

Do you have any idea of how to solve this issue?

Best regards,


Hi Albert,

Thanks for your inquriy. We will appreciate it if you please share you sample document and tags here, we will look into it and will guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,


Actually , I have found out the issue may come from the GUI using Winform.

Please close this post.

Kind regards,


Hi Albert,

Thanks for your feedback. It is good to know that you have managed to resolve the issue.

Please keep using our Aspose.Pdf and feel free to contact us for any further question or concern, we will be more than happy to extend our support.

Best Regards,