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

Unhandled exception: RadRichTextBox, HTML loading

1 Answer 99 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Yulia
Top achievements
Rank 1
Yulia asked on 04 Feb 2013, 03:09 PM
Hi, guys!
I got unhandled exception: 

System.NullReferenceException was unhandled
  Message=Object reference not set to an instance of an object.
  Source=Telerik.Windows.Documents
  StackTrace:
       at Telerik.Windows.Documents.DocumentStructure.DocumentStructureCollection.GetNextSiblingForDocumentElementOnSameLevel(LayoutBox box, DocumentElement owner) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\DocumentStructure\DocumentStructureCollection.cs:line 896
       at Telerik.Windows.Documents.Model.DocumentElementCollection.<GetEnumerator>d__0.MoveNext() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\DocumentElementCollection.cs:line 254
       at Telerik.Windows.Documents.Model.DocumentElement.<EnumerateChildrenOfType>d__0`1.MoveNext() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\DocumentElement.cs:line 377
       at Telerik.Windows.Documents.Model.DocumentElement.<EnumerateChildrenOfType>d__0`1.MoveNext() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\DocumentElement.cs:line 379
       at Telerik.Windows.Documents.Model.DocumentElement.<EnumerateChildrenOfType>d__0`1.MoveNext() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\DocumentElement.cs:line 379
       at Telerik.Windows.Documents.Model.DocumentElement.<EnumerateChildrenOfType>d__0`1.MoveNext() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\DocumentElement.cs:line 379
       at Telerik.Windows.Documents.Model.DocumentElement.<EnumerateChildrenOfType>d__0`1.MoveNext() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\DocumentElement.cs:line 379
       at Telerik.Windows.Documents.Model.DocumentElement.<EnumerateChildrenOfType>d__0`1.MoveNext() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\DocumentElement.cs:line 379
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at Telerik.Windows.Documents.Layout.SectionLayoutBox.GetEndnotesForSection(RadDocument doc, Section section) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Layout\SectionLayoutBox.cs:line 358
       at Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverride(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Layout\SectionLayoutBox.cs:line 300
       at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Layout\LayoutElement.cs:line 929
       at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Layout\LayoutElement.cs:line 832
       at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverrideInternal(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Layout\DocumentLayoutBox.cs:line 190
       at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverride(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Layout\DocumentLayoutBox.cs:line 144
       at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Layout\LayoutElement.cs:line 929
       at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Layout\LayoutElement.cs:line 832
       at Telerik.Windows.Documents.Model.RadDocument.Measure(SizeF measureSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\Model\RadDocument.cs:line 1066
       at Telerik.Windows.Documents.UI.DocumentPrintLayoutPresenter.MeasureOverride(Size availableSize) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Documents\Core\UI\DocumentPrintLayoutPresenter.cs:line 670
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
       at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Control.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
       at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Border.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Control.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
       at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
       at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
       at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Controls.Border.MeasureOverride(Size constraint)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.Window.MeasureOverrideHelper(Size constraint)
       at System.Windows.Window.MeasureOverride(Size availableSize)
       at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
       at System.Windows.UIElement.Measure(Size availableSize)
       at System.Windows.ContextLayoutManager.UpdateLayout()
       at System.Windows.ContextLayoutManager.UpdateLayoutCallback(Object arg)
       at System.Windows.Media.MediaContext.InvokeOnRenderCallback.DoWork()
       at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
       at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
       at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.DispatcherOperation.InvokeImpl()
       at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
       at System.Threading.ExecutionContext.runTryCode(Object userData)
       at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Windows.Threading.DispatcherOperation.Invoke()
       at System.Windows.Threading.Dispatcher.ProcessQueue()
       at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
       at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
       at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
       at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
       at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
       at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
       at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
       at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
       at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
       at System.Windows.Application.RunDispatcher(Object ignore)
       at System.Windows.Application.RunInternal(Window window)
       at System.Windows.Application.Run(Window window)
       at System.Windows.Application.Run()
       at WpfApplication6.App.Main() in c:\users\yuliak\documents\visual studio 2010\Projects\WpfApplication6\WpfApplication6\obj\x86\Debug\App.g.cs:line 0
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()


My XAML:
<Window x:Class="WpfApplication6.MainWindow"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <telerik:RadRichTextBox x:Name="viewer" Grid.Row="0" IsReadOnly="true" LayoutMode="Paged"/>
        <Button Grid.Row="1" Click="Button_Click">Load File</Button>
    </Grid>
</Window>

 

My Code:

private void LoadDocument(string path)
       {
           try
           {
 
               using (var stream = new FileStream(path, FileMode.Open))
               {
                   IDocumentFormatProvider provider = new HtmlFormatProvider();
 
                   RadDocument document = provider.Import(stream);
                   viewer.CommandError += OnCommandError;
                   viewer.Document = document;
               }
 
           }
           catch (Exception)
           {
 
               string str = "";
           }
       }

File HTML (code) - please save as file HTML:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<body>
  <table cellpadding="0" cellspacing="0" border="0" width="100%" class="outer" style="position: relative;">
    <tbody>
      <tr>
        <td>
            <table align="center" cellpadding="0" cellspacing="0" border="0" width="670" style="border: 0px; border-left: 1px solid #cccccc; border-right: 1px solid #cccccc; background-color: #ffffff;position: relative;">   
          <tbody>
                 <td rowspan="3"></td>
              </tbody>
 
            </table>
        </td>
       <td rowspan="3"></td>
     </tr>
     </tbody>
    </table>
 </body>
</html>

1 Answer, 1 is accepted

Sort by
0
Mihail
Telerik team
answered on 07 Feb 2013, 08:35 AM
Hello Yulia,

As we answered in your ticket on the same subject, we try to support different valid HTML input, but the main focus is on valid, XHTML-compliant and non-deprecated elements and attributes. Here, you could find more information on this topic.

Nevertheless, we have made some improvements in our HtmlFormatProvider, so with our next official 2013 Q1 version (expected at the end of this month) you might be able to import your .html file. Please note that we cannot guarantee the correct parsing of it, because of its irregularities.

I hope this information helps. Do not hesitate to contact us if you have any other questions.

In future please use forum or support to address your problems, not both systems. Thank you for understanding.

Kind regards,
Mihail
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
RichTextBox
Asked by
Yulia
Top achievements
Rank 1
Answers by
Mihail
Telerik team
Share this question
or