NullReferenceException on Docx File Import

5 posts, 0 answers
  1. Brian
    Brian avatar
    20 posts
    Member since:
    Jun 2015

    Posted 01 Oct Link to this post

    I have several documents I am importing in order to merge them into one document.  This works find on all of them but one.  On the import statement I get a null reference exception.  I have verified that the stream is not empty.  Does anyone have any clues for a work-around or fix?

    var docToBeMerged = new DocxFormatProvider().Import(fileStreamForMergeTarget);

     

    Sack Trace:

    NullReferenceException: Object reference not set to an instance of an object.

       at Telerik.Windows.Documents.Flow.FormatProviders.Docx.Model.Elements.Document.ParagraphContentElementBase.MoveInlinesToParagraph()
       at Telerik.Windows.Documents.Flow.FormatProviders.Docx.Model.Elements.Document.HyperlinkElement.OnAfterRead(IDocxImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase`3.OnAfterRead(IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.ReadChildElements(IOpenXmlReader reader, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Elements.OpenXmlElementBase.Read(IOpenXmlReader reader, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.Model.Parts.OpenXmlPartBase.Import(IOpenXmlReader reader, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.ImportXlsxPartFromArchive(ZipArchiveEntry zipEntry, OpenXmlPartBase part, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.FormatProviders.OpenXml.OpenXmlImporter`1.Import(Stream input, IOpenXmlImportContext context)
       at Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider.ImportOverride(Stream input)
       at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Import(Stream input)
       at DocumentProcessor.DocumentProcessor.GetPdf(List`1 roles, List`1 restrictedRoles, List`1 files, Boolean includeToc, Boolean includeFooter) in C:\Projects\DocumentProcessor\DocumentProcessor\DocumentProcessor.cs:line 172
       at DocumentProcessor.Default.GetPdfDoc(String role) in C:\Projects\DocumentProcessor\DocumentProcessorHarness\Default.aspx.cs:line 47
       at DocumentProcessor.Default.Test1_OnClick(Object sender, EventArgs e) in C:\Projects\DocumentProcessor\DocumentProcessorHarness\Default.aspx.cs:line 35
       at Telerik.Web.UI.RadButton.OnClick(ButtonClickEventArgs e)
       at Telerik.Web.UI.RadButton.RaisePostBackEvent(String eventArgument)
       at Telerik.Web.UI.RadButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
       
       
       

  2. Brian
    Brian avatar
    20 posts
    Member since:
    Jun 2015

    Posted 02 Oct Link to this post

    Since there are no ideas, I managed to track it down a bit further, but I still have no idea how to handle this. In the Telerik code (courtesy of JustDecompile):

    // Type: Telerik.Windows.Documents.Flow.FormatProviders.Docx.Model.Elements.Document.ParagraphContentElementBase
    // Assembly: Telerik.Windows.Documents.Flow, Version=2018.3.904.40, Culture=neutral, PublicKeyToken=5803cfa389c90ce7
    ...
    namespace Telerik.Windows.Documents.Flow.FormatProviders.Docx.Model.Elements.Document
    {
    ...
        protected void MoveInlinesToParagraph()
        {
          while (this.tempParagraph.Inlines.Count > 0)
          {
            InlineBase inline = this.tempParagraph.Inlines[0];
            this.tempParagraph.Inlines.RemoveAt(0);
            this.Paragraph.Inlines.Add(inline);
          }
        }
    ...
    }

     

    this.tempParagraph is null.  The value for the block is (as pulled from the debugger window with the client specific information removed) 

    {Paragraph}: "If you die or become disabled during a leave for qualifying military service, you become 100 percent vested in your Company matching contributions. See the  HYPERLINK \"http://myclientswebsite.com/default.aspx?DocumentId=123&TypeID=2\" Savings Plan Details  HYPERLINK \"http://myclientswebsite.com/default.aspx?DocumentId=234&TypeID=2\" Savings Plan Details  HYPERLINK \"http://myclientswebsite.com/default.aspx?DocumentId=345&TypeID=2\" Plan Details  HYPERLINK \"http://myclientswebsite.com/default.aspx?DocumentId=456&TypeID=2\" Plan Details  HYPERLINK \"http://myclientswebsite.com/default.aspx?DocumentId=567&TypeID=2\" Plan Details  HYPERLINK \"http://myclientswebsite.com/default.aspx?folderId=789&sectionId=12345&documentId=13\" "

    A lot of that will be removed later (which is part of what I am doing).  However, first I have to load it as a RadFlowDocument, and that is failing.

    So does anyone have any clues as to why this is having issues, or even better, how to resolve this?

  3. Tanya
    Admin
    Tanya avatar
    752 posts

    Posted 04 Oct Link to this post

    Hello Brian,

    I just replied in the support thread you have submitted but will answer here as well in case someone else encounters the same question. I suppose that the behavior you are observing is related to an issue which we already have logged in our portal: NullReferenceException is thrown while importing hyperlink without runs. To ensure the case is the same, I would like to test an example document which, if you would like, you can share privately in the support ticket.

    Regards,
    Tanya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  4. Brian
    Brian avatar
    20 posts
    Member since:
    Jun 2015

    Posted 04 Oct in reply to Tanya Link to this post

    Thank you!  I cannot post it publicly, but I have attached the document in question to the ticket.  Assuming that it turns out to be the case, is there some work around?  I figure it will require a change to the document, but I don't know what changes to tell the client to make the links so this does not happen.  Even if this is not the same issue, it would be good to see what would be required it so that we can make sure it does not come into play.
  5. Tanya
    Admin
    Tanya avatar
    752 posts

    Posted 05 Oct Link to this post

    Hello Brian,

    I am reposting my reply here as well:

    I confirmed that the issue is the same as the one we already have logged and modified the document you shared in the support thread by manually modifying its internal XML to remove the empty hyperlinks. They are located in document.xml and look like this:
    <w:hyperlink r:id="rId45" w:history="1"/>
    <w:hyperlink r:id="rId46" w:history="1"/>

    We are currently not sure how such a content can be produced as testing with MS Word we were unable to create empty hyperlinks. Would it be possible to ask the customers about how they create the empty elements? Which software do they use to modify the documents?

    Regards,
    Tanya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top