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

Free Support Forum - aspose.com

Changing from Evaluation to Paid License causes document builder issue

We had a strange occurrence take place when we first tested our paid license. In most cases, everything works, but we have a situation where are using a text value as a tag (as opposed to a bookmark) in order to specify where to update a table in a Word document. We need to continue to do this because of legacy documents that our client uses. Because of this, we are using the IReplacing callback class to intercept the replace, then make changes to the table and replace the tag with an empty string. This was working fine with the temporary license, and again, with the evaluation license when that expired.

When I tested it with the paid license, it stopped working, getting an out of bounds issue as described below. It took me a while to track it down and verify that the same code stops working when I change from the evaluation license to the paid license.

What I do is: get a collection of the tables in the document called allTables:

Dim allTables As Aspose.Words.NodeCollection = builder.Document.GetChildNodes(Aspose.Words.NodeType.Table, True)

In both cases, this returns four tables - 2 earlier in the document, and then two versions of my test table. For legacy reasons, then search text is in the very first cell of the table to be populated. So I locate the table I’m looking for like this:

Dim oldTable As Aspose.Words.Tables.Table = builder.CurrentNode.GetAncestor(Aspose.Words.NodeType.Table)

This finds the correct table. I can look at it in debug and see that the first cell contains the text tag that I’m looking for.

Here’s where it gets interesting. I locate the table index with the following code:

Dim oldTableIndex As Integer = allTables.IndexOf(oldTable)

This code gets a different value depending on whether I’m using the evaluation license or the paid license. The paid license version returns a 2, which would seem right based on the order of the tables in the document. The evaluation license returns a zero. If I look at allTables, though, the index does point to the correct table in both cases, they are just in different places in the collection. The problem comes in when I call:

builder.MoveToCell(oldTableIndex, row, cols, -1) ' row and cols both are zero here.

This returns an error, but only when the paid license is in effect: “System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: tableIndex”

We resolved this problem temporarily by using the following code to get the index:

Dim oldTableIndex As Integer = oldTable.ParentNode.GetChildNodes(Aspose.Words.NodeType.Table, True).IndexOf(oldTable)

This is successful with both license cases, but, depending on how complex the document is, I could see this possibly causing a problem in the future.

I’ll attach the document I’m using. I have changed the code, but if you need more than this, I can set up a version of the old code and attach that.

@steve.assurx The following code:

Document.GetChildNodes(Aspose.Words.NodeType.Table, True)

returns all tables in the document. The navigation using section.DocumentBuilder.MoveToCell is performed inside the current story of the current section. So if the tables are in different sections, the following code might return incorrect index for the current DocumentBuilder location:


Also, if I understand your requirements correctly, you can move DocumentBuilder to the desired location in IReplacingCallback using ReplacingArgs.MatchNode.

Could you please provide a sample code with your IReplacingCallback implementation? I will further investigate the issue and provide you more information.

Hi, thanks for the response. Yes, I’m finding MatchNode to find the location of the tag. I did try switching to section.DocumentBuilder.MoveToCell, but got the same results. I’ll do some more experimenting, but all that aside, it is, without a doubt, performing differently when you change the license. I’ll attach the classes:

InsertOnMatch.zip (3.7 KB)

@steve.assurx Thank you for additional information. But I cannot reproduce the problem on my side. Aspose.Words works the same with evaluation (temporary) license and normal payed license.
By inspecting your code I see the following line that, as I already mentioned, might cause the problem:

Dim allTables As Aspose.Words.NodeCollection = builder.Document.GetChildNodes(Aspose.Words.NodeType.Table, True)

You should used the following code to get the correct index of the table:

Dim oldTableIndex As Integer = oldTable.ParentNode.GetChildNodes(Aspose.Words.NodeType.Table, False).IndexOf(oldTable)

Also you can use code like the following to avoid using MoveToCell method:

' -- get the row ancestor of the current node (where the builder cursor is)
Dim currentRow As Aspose.Words.Tables.Row = builder.CurrentNode.GetAncestor(Aspose.Words.NodeType.Row)

For Each c As System.Data.DataColumn In dataLinkData.Columns
    cols = cols + 1
1 Like

Okay thank you. I do have it working with the correct code. Thanks for the “currentRow” code, too, that’s good to know. I’ll consider this closed, and I appreciate the help.

Regarding the license issue, I think you’ll eventually find that something is different based on the licenses. If it helps, the temporary license that worked with the original code was called “Aspose.Total.Product.Family.lic”, and the paid license that did not was called “Aspose.Total.NET.lic”

  • Steve

@steve.assurx It is perfect that you have managed to make the code to work properly.
But still I do not see any scenario where Aspose.Words can behave differently depending on license type. It can work either in evaluation mode(the license is not set) or in licensed mode(the license is set, does not matter what type of license).

The reason I came to that conclusion is, the exact same code behaved differently when the only change made was to remove the set license code. I demonstrated it back and forth for my boss, he drilled down into everything and came to the same conclusion. Since it wasn’t the right method, it probably doesn’t matter.

I don’t know anything about the licenses, but if the evaluation mode has limitations within the same library, it has to be running different code in some places. That doesn’t necessarily mean anything, I’m just wanted to let you know what I saw, and, at this point, it is just for your information since everything is working fine for us in both cases now.

@steve.assurx Yes, if you remove the set license code, Aspose.Words works in evaluation mode with limitations. I must have misunderstood you, I was concluded that you have used a temporary license for testing and code worked differently when you use temporary and payed licenses. But it seems the code is working differently when you run it in evaluation and licensed mode. This definitely can occur because Aspose.Words truncates the document in evaluation mode and injects an evaluation watermark, that can lead into document object model differences between evaluation and licensed modes.

That makes sense. Thank you for your help on this subject, for pointing me in the right direction, and for pointing out using the row ancestor, I really appreciate it!