UpdateFields Error

I have the following line in my code:
doc.Range.UpdateFields();
On running that code, I received the error below:

System.InvalidCastException: Unable to cast object of type 'Aspose.Words.FieldStart' to type 'Aspose.Words.FieldSeparator'. at ա.ጎ.VisitFieldEnd(FieldEnd fieldEnd) 
at Aspose.Words.FieldEnd.Accept(DocumentVisitor visitor) 
at Aspose.Words.CompositeNode.࠭(DocumentVisitor ࠮) 
at Aspose.Words.Paragraph.Accept(DocumentVisitor visitor) 
at Aspose.Words.CompositeNode.࠭(DocumentVisitor ࠮) 
at Aspose.Words.Body.Accept(DocumentVisitor visitor) 
at Aspose.Words.CompositeNode.࠭(DocumentVisitor ࠮) 
at Aspose.Words.Section.Accept(DocumentVisitor visitor) 
at Aspose.Words.CompositeNode.࠭(DocumentVisitor ࠮) 
at Aspose.Words.Document.Accept(DocumentVisitor visitor) 
at ա.ጎ.ጒ(Node ࠂ) at ա.ጎ.ጓ(Node ࠂ) 
at Aspose.Words.Range.UpdateFields() 

What can be causing this? It seems to be happening only in documents that have been edited in MS Word 2007 with track changes turned on.
Any help is appreciated.
Thank you.

Hi
Thanks for your request. Could you please attach your document for testing? I will investigate this problem and provide you more information.
Best regards.

File attached.
Thank you.

Hi
Thanks for additional information. I can’t reproduce this issue on my side. I use the latest version of Aspose.Words (5.1.0) for testing.
Here is my code.

Document doc = new Document(@"Test120\9372.doc");
doc.Range.UpdateFields();
doc.Save(@"Test120\out.doc");

Best regards.

I updated Aspose in my program to the latest version & I’m still receiving the same error. Before I update the fields, I first accept all revisions. Can that be making a difference?

Document ThisDocument = oldDocument;
InitiateLicense();
WorkDocClone.AcceptAllRevisions();
doc.Range.UpdateFields();

Hello!
I have tried with AcceptAllRevisions and haven’t got the error:

private static void TestUpdateFields()
{
    Document doc = new Document("9372.doc");
    doc.AcceptAllRevisions();
    doc.Range.UpdateFields();
    doc.Save("9372_out.doc");
}

(This function was called in my test after initializing the license.)
Please try the minimal sample first. If it works then we’ll looks what could be wrong in your code. If it doesn’t work on your side then we’ll think about any special tests to diagnose this.
Note that when you assign reference type variables only references are copied, no objects created:

Document ThisDocument = oldDocument;

Also can you explain what WorkDocClone in your code is? A property or a variable? Please show how you obtain it.
Regards,

Thank you very much for your help. I tried the mimal test above & that did not throw any errors. Below is the exact code which I’m using that is throwing the error, and the document is attached. What’s wrong here?

public static void PrepareDoc()
{
    Document WorkDoc = new Document("C:/DocuMed/9930.doc", LoadFormat.Doc, null); 
    Document WorkDocClone = WorkDoc;
    WorkDocClone.AcceptAllRevisions();
    WorkDocClone.Range.UpdateFields();
}

Hi
I still can’t reproduce this issue on my side. I tried to use the same code as you. Please make sure that you are using the latest version of Aspose.Words in your application.
Best regards.

It seems the wrong document was attached, since when I downloaded it, it was a different size then my original. Attached is the document again.

Hi
Thanks for additional information. I managed to reproduce this problem on my side. I have created new issue #4960 in our defect database. I will notify you as soon as it is fixed.
Best regards.

Thank you. Has there been any progress on this? When can I expect this fix to be completed?

Hi
Thanks for your request. Unfortunately this issue is unresolved yet. Currently I can’t provide you exact date when this will be fixed.
Best regards.

The issues you have found earlier (filed as 4960) have been fixed in this update.