While attempting to convert a document from .docx to .rtf, a call to the Document.Save() operation fails with a Null Reference Exception. I’ve included the stack trace and a snippet of the calling code. Please advise on how to resolve or work around this issue.
Stack Trace:
at .(Paragraph )
at .VisitParagraphStart(Paragraph )
at Aspose.Words.Paragraph.r3ka8zscesabkstb24kjjv9sml9wq7pw (DocumentVisitor )
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Paragraph.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Body.Accept(DocumentVisitor visitor)
at .VisitSectionEnd(Section )
at Aspose.Words.Section.r3ka8zscesabkstb24kjjv9sml9wq7pw (DocumentVisitor )
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Section.Accept(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptChildren(DocumentVisitor visitor)
at Aspose.Words.CompositeNode.AcceptCore(DocumentVisitor visitor)
at Aspose.Words.Document.Accept(DocumentVisitor visitor)
at . ( )
at . ( )
at Aspose.Words.Document.( )
at Aspose.Words.Document.(Stream , String , SaveOptions )
at Aspose.Words.Document.Save(Stream stream, SaveOptions saveOptions)
at AsposeSandbox.Program.ConvertToRtf() in \..\source\repos\AsposeSandbox\Program.cs:line 45
Failing Method:
private static byte[] ConvertToRtf()
{
// The offending file is a .docx document with a 199 revisions.
var testFileInfo = new FileInfo("TestDocument.docx");
var stream = new MemoryStream();
Document doc = new Document(testFileInfo.FullName);
SaveOptions saveOptions = SaveOptions.CreateSaveOptions(SaveFormat.Rtf);
// Calling Save() results in an obfuscated Null Object exception.
doc.Save(stream, saveOptions);
return stream.ToArray();
}
TestDocument.docx (24.4 KB)