We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Bookmark.Text value different from variable assigned to Bookmark.Text - odd behavior

Hi,

I’m getting some strange behavior from Aspose when I try to change the text of a certain bookmark. Essentally I want to loop through a document, and set the text of any bookmark which is simply “#” to empty.

Here is a snippet of my code:

foreach (Aspose.Words.Bookmark bm in doc.Range.Bookmarks)
{
string temp = bm.Text;
string temp2 = bm.Text.Trim();

 if (temp2 == "#")
 {
       bm.Text = "";
 }

}

For the problem bookmark in question, I’m finding that bm.Text = “\r”, temp = “#\r” and temp2 = “#”. Then when I try to set bm.Text I get an error:

System.ArgumentException occurred
HResult=0x80070057
Message=Cannot insert a node of this type at this location.
Source=Aspose.Words
StackTrace:
at Aspose.Words.CompositeNode.(Node , Node , Boolean )
at Aspose.Words.CompositeNode.(Node , Node , Node )
at .()
at .( )
at .()
at Aspose.Words.Bookmark.set_Text(String value)

I can’t see any reason why “temp” should ever be different from bm.Text since that’s what its assigned to, but nevertheless that’s what it does! If I put a breakpoint into my code and step through, the error doesn’t occur, which makes me think that this is some kind of weird timing issue in Aspose itself.

I can PM the problem document to anyone who is interested, but my client would rather I not post it on a public forum.

Thanks,

Adam

@AdamEth,

Thanks for your inquiry. Unfortunately, it is difficult to say what the problem is without the document you are getting this problem with. We need this problematic document to reproduce the same exception on our end.

It is safe to attach files in the forum. If you ZIP and attach your document here, only you and Aspose staff members can access/download it.

You can also remove any sensitive information by replacing it with dummy data instead.

Best regards,
Awais Hafeez

Okay, I’ve attached the document. The specific bookmark causing the issue is named “ACN”. I’m also having an issue where text entered into “ContractDate” doesn’t appear, but that’s not actually throwing an exception.

Killara Contract Extra (1).zip (588.9 KB)

Thanks,

Adam

@AdamEth,

Thanks for your inquiry.

After an initial test with licensed version of ‘Aspose.Words for .NET’ 17.6, we were unable to reproduce this issue on our end when running above code for ‘Killara Contract Extra (1).docx’ document. Please upgrade to the latest version of Aspose.Words for .NET and see how it goes on your end. Hope, this helps.

In case the problem still remains, please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end, ZIP and attach it here for testing. Thanks for your cooperation.

Best regards,
Awais Hafeez