Hi,
I’m getting random exceptions while adding a text stamp on a PDF document.
I say “random” as in flacky parallel unit tests because most of the times those tests pass but I cannot figure out why they randomly fail.
This is the stack trace that I get from Aspose.PDF 22.4:
System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Text.TextSegmentCollection.#=ze$KTyoanEEhe.get_Current()
at Aspose.Pdf.TextStamp.Put(Page page)
at Aspose.Pdf.Page.AddStamp(Stamp stamp)
With 22.5 I have the same exception, albeit with a different encrypted location:
System.NullReferenceException: Object reference not set to an instance of an object.
at Aspose.Pdf.Text.TextSegmentCollection.#=zzMwSyrvK2gaP.get_Current()
at Aspose.Pdf.TextStamp.Put(Page page)
at Aspose.Pdf.Page.AddStamp(Stamp stamp)
This is (roughly) the code that I’m using:
var outputStream = new MemoryStream();
using (Document inDoc = GetAsposeDocument(inputDocument)) // new Aspose.Pdf.Document
{
var firstPage = inDoc.Pages.FirstOrDefault()
?? throw new InvalidOperationException(...);
var stamp = new TextStamp(textToWrite, new Aspose.Pdf.Text.TextState
{
FontSize = fontSize, // 11
ForegroundColor = Color.FromArgb(argbColor.R, argbColor.G, argbColor.B),
Font = Aspose.Pdf.Text.FontRepository.FindFont("Times", Aspose.Pdf.Text.FontStyles.Regular, ignoreCase: true),
});
switch (orientation)
{
case PdfStampOrientation.Left:
stamp.VerticalAlignment = VerticalAlignment.Center;
stamp.HorizontalAlignment = HorizontalAlignment.Left;
stamp.RotateAngle = 90;
stamp.LeftMargin = 20;
break;
case PdfStampOrientation.Right:
// ^ Likewise, error happens in either case...
break;
default:
// ^ Likewise, error happens in either case...
break;
}
firstPage.AddStamp(stamp); // <===== HERE THROWS THE EXCEPTION
inDoc.Save(outputStream);
}
I think that this is related to some multithread access because tests are run in parallel, but this kind of issue takes a long time to diagnose without some internal knowledge of what the library is doing.
I won’t ask you to try to reproduce the issue but I’d like to have some hint on what exactly is breaking in the library in order to narrow down the possible problem on my end before submitting an example that is sistematically broken.
Since the dll is encrypted and the exception does not have a message can you please share some hypotesis on what is going wrong?
Thanks in advance.