Dear Aspose team!
A strange problem occured after removing bookmarks from a document.
The following steps are executed:
1. looking up particular bookmarks (not all!) from Document#Range#Bookmarks, filtered by name patterns
2. storing the found bookmarks in a separate list
3. iterating over the list:
a) filling the table which is nested in each bookmark
b) removing the bookmark by calling Bookmark#Remove() immediately after filling it
4. getting the remaining bookmarks from the document by Document#Range#Bookmarks again
5. starting a new iteration to remove each remaining bookmark with its content
In 4, I get a BookmarkCollection that contains all bookmarks that should have been removed in 3b) even twice!!!
5. raises an exception because the bookmark is already removed (start and end have no parent):
System.InvalidOperationException: Cannot find bookmark 'XY' in the document.
At first, I thought that there could be a concurrent modification problem: iterating over the BookmarkCollection in Range and removing the bookmarks during the iteration. But as you can see in 2., they are stored in a separate list to make them ready for removal.
Do you know what could have happened?
Please let me know if you require source code or the document. The sources are a little more complex because we use a layer that is abstracting from Aspose.Words (by adapter classes).
Thanks a lot for your help,