Using the above code trying to get the StyleChanges and Rejecting them from ChangesInfo[] and Update it to ICompareResult set, but it throws an exception as “Object reference not set to an instance” for some records in ChangeInfo[] list.
We cannot reproduce this issue using API version 20.7 and following code:
using (Comparer comparer = new Comparer("source.docx"))
{
comparer.Add("target.docx");
comparer.Compare();
ChangeInfo[] changes = comparer.GetChanges();
changes[0].ComparisonAction = ComparisonAction.Reject;
comparer.ApplyChanges(File.Create("result.docx"), new SaveOptions(), new ApplyChangeOptions() { Changes = changes });
}
Have a look at the migration notes and this documentation article.
Please try this code example and let us know if issue persists. You can also download sample project from GitHub.
@atirtahir3 Installed the latest Groupdocs.Comparison dll version 20.7.0.0, used the suggested code but getting an exception “The type initializer for ‘Aspose.CAD.Image’ threw an exception.” at comparer.Compare().
In my application we are using Aspose.Word V 16.4.0.0 dll.
Please help me out.
Hi, thank you for your quick response. Before compare am modifying the document by removing TOC from it and passing the same document as a source file to the Compare. When applying the changes to compare result an exception is thrown as “Object reference not set to an instance”. So am getting the execption when i remove the TOC, without that am not facing any issue with ApplyChanges() .
@atirtahir3 can you help me out here, as i need to remove the TOC from the source and destination document before compare.
Please have a look at this screencast - Remove TOC and compare.zip (3.8 MB). We are using the source-code that you shared to remove TOC of SourceDoc.docx and then we used the resultant document as a source for comparison purpose.
Can you please prepare a sample (e.g. console) application using that issue could be reproduced? We’ll then further investigate this matter.
NOTE: We cannot reproduce this issue even without applying license.
@atirtahir3 As you shared a screencast in that result your getting the TOC in output document. But we need to remove it in both Source and destination then need to compare.
We removed TOC from both source and destination documents. Then compared them, there was no issue. Please share a simple console application to reproduce this issue.
As i mentioned in this comment when ApplyChanges() are done an exception is thrown.
GroupDocs.Comparison.Result.ChangeInfo[] changes = comparer.GetChanges();
for (int i = 0; i < changes.Length; i++)
{
if (changes[i].Type == GroupDocs.Comparison.Options.ChangeType.StyleChanged)
{
changes[i].ComparisonAction = GroupDocs.Comparison.Result.ComparisonAction.Reject;
}
}
comparer.ApplyChanges(resultPath, new ApplyChangeOptions { Changes = changes });
Can you please test this at your end,
1.Get changes from compare using comparer.GetChanges().
2.Using for loop Reject the StyleChanges and apply the changes to comparer.
3.Then an exception is thrown when ApplyChanges() are done.
@atirtahir3 Instead of console application am sharing you the code which i did after compare is done and when exception is thrown
Yes, this issue is now reproduced at our end. Hence, we’ve logged it in our internal issue tracking system with ID COMPARISONNET-2423 for further investigation and resolution. As there’s any update, you’ll be notified.
@atirtahir3 Can i create the duplicate object of comparer resutl, as i have a requirement where i need to use the original compare result after the ApplyChanges are done.
1.Need to create a duplicate object of compare result.
2.When ApplyChanges() are done to the original(comparer) result the changes should not be reflected in duplicate object.