DocumentBuilder PageSetup & CurrentSection have a Null Reference

After removal of a CompositeNode utilizing .Remove() the Document Builder’s Current Section and Page Setup have a Null Reference Exception. The composite node in question derives from the ReplacingArgs.MatchNode.

I can still further modify/save the document after this occurs and the node in question is removed, but the DocumentBuilder will throw an exception when attempting to call the Page Setup.

I also attempted to utilize JoinRunsWithSameFormatting() on the document prior to the removal, which has no resolution.

@jmenagh Could you please create a simple code that will allow us to reproduce the problem and provide it here along with document? We will check the issue and provide you more information.

At this time, I’m not able to submit any code or document due to company restrictions. However, what would cause this situation based on the Aspose code?

@jmenagh The problem might occur because the current paragraph of DocumentBuilder is removed. For example see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.CurrentParagraph.Remove();
// This will throw.
PageSetup ps = builder.PageSetup;

Thank you. I believe the removal of the CurrentParargraph was the underlying issue.

1 Like