I'm getting an error when converting some docs with field codes to PDF. It isn't all field codes, because the TOC works fine. I am attaching a document that just contains one of the field codes causing problems. If there is any possible workaround, short of having users delete their field codes, I'd be interested in hearing it. The full stack trace and some example code is below.
ERROR MESSAGE:
Unable to cast object of type 'Aspose.Words.Fields.FieldSeparator' to type 'Aspose.Words.Run'. <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidCastException: Unable to cast object of type 'Aspose.Words.Fields.FieldSeparator' to type 'Aspose.Words.Run'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
[InvalidCastException: Unable to cast object of type 'Aspose.Words.Fields.FieldSeparator' to type 'Aspose.Words.Run'.] ᰻.∮.∸(Field Ẓ) +383 㘖.㘕.VisitFieldStart(FieldStart fieldStart) +825 Aspose.Words.Fields.FieldStart.Accept(DocumentVisitor visitor) +22 Aspose.Words.CompositeNode.Շ(DocumentVisitor Ո) +83 Aspose.Words.Paragraph.Accept(DocumentVisitor visitor) +83 Aspose.Words.CompositeNode.Շ(DocumentVisitor Ո) +83 Aspose.Words.Tables.Cell.Accept(DocumentVisitor visitor) +83 Aspose.Words.CompositeNode.Շ(DocumentVisitor Ո) +83 Aspose.Words.Tables.Row.Accept(DocumentVisitor visitor) +83 Aspose.Words.CompositeNode.Շ(DocumentVisitor Ո) +83 Aspose.Words.Tables.Table.Accept(DocumentVisitor visitor) +83 Aspose.Words.CompositeNode.Շ(DocumentVisitor Ո) +83 Aspose.Words.Body.Accept(DocumentVisitor visitor) +83 㘖.㘕.ℭ(Section ọ) +233 㘖.㘕.Ω(⅓ ℧) +1499 Aspose.Words.Document.ӿ(Stream ӹ, String ӷ, SaveFormat Ԁ) +140 Common_ConvertToPDF.btnConvert_Click(Object sender, EventArgs e) +354 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981 |
CODE SAMPLE (where FileToConvert is from an upload control):
Dim uploadedDocument As New Document(Me.FileToConvert.FileContent)
uploadedDocument.SaveOptions.PdfExportImagesFolder = System.IO.Path.GetTempPath()
Using intermediateDocument As New System.IO.MemoryStream
uploadedDocument.Save(intermediateDocument, SaveFormat.AsposePdf)
Dim pdfDocument As New Aspose.Pdf.Pdf
pdfDocument.BindXML(intermediateDocument, Nothing)
Using resultBuffer As New System.IO.MemoryStream
pdfDocument.Save(resultBuffer)
DeliverBytes(resultBuffer.ToArray(), newName)
End Using
End Using