Null reference exception when importing html fragment

5 posts, 1 answers
  1. John
    John avatar
    14 posts
    Member since:
    Feb 2012

    Posted 10 Apr 2012 Link to this post

    I exported HTML from the RadRichTextBox as a fragment and then later tried to import this fragment back into a new RadRichTextBox.  It blows up with a null reference exception when I try to import it back in.  It worked with no errors when I used the default export options. Are fragments not possible to round trip with RadRichTextBox?

    HtmlFormatProvider prov = new HtmlFormatProvider();
    prov.ExportSettings = new HtmlExportSettings()
        {
            DocumentExportLevel = DocumentExportLevel.Fragment,
            StylesExportMode = StylesExportMode.Inline
        };
    string data = prov.Export( _editor.Document );
     
    // later...
     
    HtmlFormatProvider prov2 = new HtmlFormatProvider();
    _editor.Document = prov2.Import( data );    // this line gets the null reference exception at the location below


       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ConvertToFontStyle(Object value)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.CreateSpanFromTextNode(INode childNode)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ProcessContentNode(INode node)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.<>c__DisplayClass3.<ProcessNode>b__2()
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ProcessNode(INode node)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ProcessGenericNode(INode node)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.<>c__DisplayClass3.<ProcessNode>b__2()
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ProcessNode(INode node)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ProcessParagraphNode(INode node)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.<>c__DisplayClass3.<ProcessNode>b__2()
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ProcessNode(INode node)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ProcessGenericNode(INode node)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.<>c__DisplayClass3.<ProcessNode>b__2()
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.ProcessNode(INode node)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.Import.HtmlDocumentImporter.Import(Stream input)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.HtmlFormatProvider.Import(Stream input)
       at Telerik.WinControls.RichTextBox.FileFormats.Html.HtmlFormatProvider.Import(String input)
       at Documents._list_SelectedValueChanged(Object sender, EventArgs e) in DocumentsTab.cs:line 99

    Fragment contents:
    <p style="margin: 0px 0px 0px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px;">
        <span style="font-family: 'Arial';font-style: ;font-weight: bold;font-size: 13.33333px;color: #000000;text-decoration: underline;">High return net</span>
    </p>
    <p style="margin: 0px 0px 0px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px;">
        <span style="font-family: 'Arial';font-style: ;font-weight: bold;font-size: 13.33333px;color: #000000;text-decoration: underline;">High return gross</span>
    </p>
    <p style="margin: 0px 0px 0px 0px;text-align: left;text-indent: 0pt;padding: 0px 0px 0px 0px;">
        <span style="font-family: 'Arial';font-style: normal;font-size: 13.33333px;color: #000000;">See handbook page 128</span>
    </p>
  2. John
    John avatar
    14 posts
    Member since:
    Feb 2012

    Posted 10 Apr 2012 Link to this post

    Playing with the markup, it looks like what it does not like is the empty "font style: ;"  values.  If I manually edit this markup and change these to "font style: normal;" it does not blow up.  I am not sure what I can do about this programatically though. 
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Svett
    Admin
    Svett avatar
    728 posts

    Posted 13 Apr 2012 Link to this post

    Hello John,

    Thank you for contacting us.

    I have managed to reproduce the described issue. It is caused by the missing value for the font-style attribute. I cannot provide you with a work around, due to internal implementation of the format provider. I have logged this issue and you can track it in our public issue tracking system.

    Your Telerik points have been updated for this report.

    Let us know if you have any other questions or suggestions.

    Regards,
    Svett
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  5. Answer
    MARCO
    MARCO avatar
    3 posts
    Member since:
    Sep 2010

    Posted 06 Jun 2012 Link to this post

    I know this is a quite old thread, but maybe it can help someone else.

    A quick workaround to this, is executing a replace in the string exported by the provider, as follows:

    var prov = new HtmlFormatProvider
                {
                    ExportSettings = new Telerik.WinControls.RichTextBox.FormatProviders.Html.HtmlExportSettings
                    {
                        DocumentExportLevel =
                            Telerik.WinControls.RichTextBox.FormatProviders.Html.DocumentExportLevel.Fragment,
                        StylesExportMode =
                            Telerik.WinControls.RichTextBox.FormatProviders.Html.StylesExportMode.Inline
                    }
                };
     
    var exportResults = prov.Export(txtDetalhe.Document).Replace("font-style: ;", "");

    Hope this helps.

    Regards
  6. Michael Hilgers
    Michael Hilgers avatar
    76 posts
    Member since:
    Apr 2010

    Posted 20 Jun 2012 Link to this post

    Thx Marco, this workaround helps!
Back to Top
UI for WinForms is Visual Studio 2017 Ready