UpdateFields function throwing error when adding Index entries inside section

Hi team,

When merging and updating fields using UpdateFields() from two word documents into main document having indexes inside sections is throwing Stack Empty error.

Steps to reproduce:

  1. Create two word documents(viz., MarkEntryDoc and IndexInsertDoc) and add sections with some data in it.
  2. Now in MarkEntryDoc add a mark entry index to some data and mark it.
  3. In IndexInsertDoc insert the index, when click on ok, it should show No index entries found.
  4. Now try to append the 2 word documents in a single word document and execute UpdateFields() function to run all the fields and expose the data from the Indexes created
  5. But the above UpdateFields() function throws stack empty error.

If we are removing the sections inside the word document and adding normal text and follow from step 3, you’ll not find any error and runs by adding the indexed data to the new document.

Here is the attached console application that produces the issue. Please change path/s as required in the code.

SectionIndexing.7z (5.0 MB)

IndexInsert.docx (21.2 KB)

MarkEntry.docx (23.2 KB)

Thanks.

@manikya.rao
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-26492

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

PS: As I can see in your code you are inserting hidden PAGE fields at the beginning and at the end of bookmarks. Looks like such approach is used to determine page number where bookmarks start and end. There is much easier approach using LayoutCollector to achieve the same:

LayoutCollector collector = new LayoutCollector(document);
var bookmarks = document.Range.Bookmarks;

foreach (Bookmark bookmark in bookmarks)
{
    var bookmarkName = bookmark.Name;
    if (!bookmarkName.StartsWith("RG_OBJECT_CONTENT_", StringComparison.Ordinal))
        continue;

    BookmarkStart bookmarkStart = bookmark.BookmarkStart;
    BookmarkEnd bookmarkEnd = bookmark.BookmarkEnd;

    int bkStartPage = collector.GetStartPageIndex(bookmarkStart);
    int bkEndPage = collector.GetStartPageIndex(bookmarkEnd);
}

Hi @alexey.noskov

I understood, that’s different part of the code we’ve used. Even if I remove the code of inserting bookmarks, I’m able to see the same issue with UpdateFields().

Just FYI The sections of the word document has the Indexes which is throwing the error and also right before the updatefields method execution we’re seeing the main document has the marked index data which is kind of expected.

Thanks.

@manikya.rao Yes, we have managed to reproduce the problem on our side and logged it as WORDSNET-26492. We will keep you updated and let you know once it is resolved.

The issues you have found earlier (filed as WORDSNET-26492) have been fixed in this Aspose.Words for .NET 24.3 update also available on NuGet.