Duplicate Bookmark Positions Results in lost bookmarks or worse


Problem: When Assigning a value to Aspose.Words.Bookmark.Text when a second bookmark exists (See Attached FiveBookmarks.doc) with the same position I am intermittently getting three different results, two of which appear to be bugs.

1) After assigning a value to Aspose.Words.Bookmark.Text using a for each loop, one of the bookmark items in the Document.Range.Bookmarks collection vanishes. (90% of the time).

2) I get the attached error (See attachment Error.txt) "Aspose.Words.PleaseReportException : Cannot find bookmark..."

3) Everything works as expected (this rarely happens)

Sample Code....

#region TestBookmark.TestPopulateBookmarksBug()


public void TestPopulateBookmarksBug()


FormDefinition formDefinition = TestFormDefinition.FormDefinitionFactory(TestHelper.GetUnderwritingCompany);

FormDefinitionVersion formDefinitionVersion = formDefinition.Versions[0];

formDefinitionVersion.FileName = FiveBookmarkDocument;

MicrosoftWordWrapper microsoftWordWrapper = new MicrosoftWordWrapper(formDefinitionVersion);

Dictionary<string, string> bookmarks = microsoftWordWrapper.BookMarks;

CreateBookmarks(bookmarks, formDefinitionVersion);

//Count is 6

int countBefore = microsoftWordWrapper.BookMarks.Count;


//Count suddenly becomes 5

//One of the bookmards in the Document vanishes

int countAfter = microsoftWordWrapper.BookMarks.Count;

Assert.AreEqual(countBefore, countAfter);



#region MicrosoftWordWrapper.TestPopulateBookmarksWithDataBug()

public void TestPopulateBookmarksWithDataBug()


foreach (Aspose.Words.Bookmark wordBookmark in Document.Range.Bookmarks)


wordBookmark.Text = string.Empty;





The attached document 'FiveBookmarks.doc' has six bookmarks and none of them has the same position with the other or has a name 'NEWbookmark' as in the attached error message.

However, if the document has overlapping or nested bookmarks then settinng the text of containing or overlapping bookmark will effectively destroy the nested bookmark or bookmark start/end node in case of overlapping bookmark. This bookmark will seize to exist in the document after that and cause the error like you have described. That behavior is by design and could not changed for the time being. We are going to improve our bookmark, field and range handling in one of the future versions. That will help to avoid situations like this.

Best regards,


Yes, sorry. I recreated the document that causes this error. Please check out the attached document “DuplicateBookmark.doc”. The two bookmarks “Duplicate2” and “Duplicate3” are not nested bookmarks but bookmarks in the same position.


That is exactly the case that was described in my previous post. Use DocumentExplorer sourse code demo to see how bookmark start and end nodes are located in your document. For 'duplicate' bookmarks they are going like this






So when for example you set Text of bookmark "Duplicate2" to some value - the BookmarkStart node of "Duplicate3" bookmark is destroyed and the bookmark end also gets destroyed to keep the document well formed. That is how it is implemented now. We will improve this behavior - but later.