This is a migrated thread and some comments may be shown as answers.

Null reference exception when importing html fragment

4 Answers 274 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 10 Apr 2012, 08:36 PM
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>

4 Answers, 1 is accepted

Sort by
0
John
Top achievements
Rank 1
answered on 10 Apr 2012, 08:57 PM
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. 
0
Svett
Telerik team
answered on 13 Apr 2012, 12:38 PM
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 >>
0
Accepted
MARCO
Top achievements
Rank 1
answered on 06 Jun 2012, 02:12 PM
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
0
Michael Hilgers
Top achievements
Rank 1
answered on 20 Jun 2012, 11:15 AM
Thx Marco, this workaround helps!
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
John
Top achievements
Rank 1
Answers by
John
Top achievements
Rank 1
Svett
Telerik team
MARCO
Top achievements
Rank 1
Michael Hilgers
Top achievements
Rank 1
Share this question
or