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

InvalidCastException when loading some Docx

5 Answers 214 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Rashad Rivera
Top achievements
Rank 1
Rashad Rivera asked on 13 May 2011, 02:44 AM
Hello All,

   One of my customers tried to load a document into an application I developed for them that uses the RadRichTextBox and they received the following exception.  The document can not be attached but I found a document on the internet that causes the same result:

- Document: http://ecn.channel9.msdn.com/o9/learn/Silverlight4/Labs/RichTextBox/RichTextBox%20Lab.docx 

Basically, I don't need the document to load (although that would be nice), I just need the RadRichTextBox to not exploded.  You know, for stability's sake. 


Message: Unhandled Error in Silverlight Application
Code: 4004
Category: ManagedRuntimeError
Message: System.InvalidCastException: Unable to cast object of type 'Telerik.Windows.Documents.Model.BookmarkRangeStart' to type 'Telerik.Windows.Documents.Model.AnnotationRangeEnd'.
at Telerik.Windows.Documents.Model.RadDocument.PairAnnotationRanges(IEnumerable`1 annotationMarkers)
at Telerik.Windows.Documents.Model.RadDocument.PairAnnotationRanges()
at Telerik.Windows.Documents.Layout.DocumentLayoutBox.UpdateGlobalProperties()
at Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverride(SizeF availableSize)
at Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(SizeF availableSize)
at Telerik.Windows.Documents.Layout.LayoutElement.Measure(SizeF availableSize)
at Telerik.Windows.Documents.Model.RadDocument.Measure(SizeF measureSize)
at Telerik.Windows.Documents.UI.DocumentPrintLayoutPresenter.MeasureOverride(Size availableSize)
at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)

Line: 120
Char: 13
Code: 0
URI: http://localhost:6519/

5 Answers, 1 is accepted

Sort by
0
Iva Toteva
Telerik team
answered on 18 May 2011, 08:35 AM
Hi Rashad Rivera,

Thank you for getting to us about this bug. Our policy is to try and import documents with minimal loss (if there are document elements that go beyond the supported ones in RadDocument). In case the import is unsuccessful, a MessageBox should be shown. There are rare cases when the document is supposedly imported properly and a problem occurs afterwards.
We will look into the import and provide a fix in the next release (Q2 2011 Beta), which is due in mid-June at latest.
We are sorry for he inconvenience caused. Your Telerik points have been updated in appreciation for the bug report.

Regards,
Iva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jerrica
Top achievements
Rank 1
answered on 28 Jul 2011, 03:04 PM
Hi Iva

I'm just following up on this.  I have the Q2 release, but still get this error. 
Can you please have a look at my code to see if I did something wrong?

RadDocument

 

 

doc = new RadDocument();

 

 

 

IDocumentFormatProvider provider = DocumentFormatProvidersManager.GetProviderByExtension(extension);

 

 

 

if (provider != null)

 

{

doc = provider.Import(stream);

}

 

 

else

 

{

 

 

MessageBox.Show("Unknown format.");

 

 

 

return;

 

}

 

 

//Get Error Here!!

 

doc.Measure(

 

RadDocument.MAX_DOCUMENT_SIZE);

 

doc.Arrange(

 

new RectangleF(PointF.Empty, doc.DesiredSize));

 

 

 

//

 

doc.LayoutMode =

 

DocumentLayoutMode.Paged;

 

doc.DefaultPageLayoutSettings.Width = 320/0.4F;

doc.DefaultPageLayoutSettings.Height = 390/0.35F;

doc.SectionDefaultPageMargin =

 

new Padding(20);

 

doc.Sections.First.PageMargin =

 

new Padding(20);

 

//Get Error Here!!

 

doc.UpdateLayout();

 

 


this
.book.RightPageIndex = 0;

 

 

 

 

this.viewManager.Document = doc;

 

bindingSource.Document = doc;

Thanks
Jerrica

0
Ivailo Karamanolev
Telerik team
answered on 02 Aug 2011, 12:20 PM
Hello Jerrica,

There has been an issue with the import of some documents with the Q2 release. It has been fixed in the LIB (Latest Internal Build, version 2011.2.0801). Please try importing the document with that version, and if it still fails, contact us through the support system attaching a sample documents that can't be imported.

Best wishes,
Ivailo
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Rashad Rivera
Top achievements
Rank 1
answered on 16 Sep 2011, 04:36 AM
Your RadRichTextBox is just to unstable.  I found another issue where the following code executes fine, but after the method returns, the UI thread is locked by your internal processes.   Also, before you ask: "NO" I can't give you a code sample.  You guys always ask and I don't have time to play "QA".
string radTextBoxXaml = @"<tCtr:RadRichTextBox xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:tCtr='clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Documents'
IsSelectionMiniToolBarEnabled='False'
IsContextMenuEnabled='False'
IsSpellCheckingEnabled='False'
IsReadOnly='True'
LayoutMode='Flow'
BorderThickness='0'
Padding='0'
BorderBrush='Transparent'
HorizontalScrollBarVisibility='Disabled'
HyperlinkNavigationMode='Click'><t:RadDocument xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns:t='clr-namespace:Telerik.Windows.Documents.Model;assembly=Telerik.Windows.Documents' DefaultPageLayoutSettings='816,1056' LayoutMode='Flow' PageViewMargin='10,10'>
<t:RadDocument.Lists>
<t:ListSerializationData ID='1' StyleID='1' />
<t:ListSerializationData ID='2' StyleID='2' />
<t:ListSerializationData ID='3' StyleID='3' />
</t:RadDocument.Lists>
<t:RadDocument.ListStyles>
<t:ListStyle ID='1'>
<t:ListLevelStyle LevelText='{}{0}.' NumberingFormat='Decimal' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{1}.' NumberingFormat='LowerLetter' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{2}.' NumberingFormat='LowerRoman' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{3}.' NumberingFormat='Decimal' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{4}.' NumberingFormat='LowerLetter' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{5}.' NumberingFormat='LowerRoman' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{6}.' NumberingFormat='Decimal' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{7}.' NumberingFormat='LowerLetter' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{8}.' NumberingFormat='LowerRoman' StartingIndex='1' />
</t:ListStyle>
<t:ListStyle ID='2'>
<t:ListLevelStyle FontFamily='Symbol' LevelText='?' NumberingFormat='Bullet' StartingIndex='1' />
<t:ListLevelStyle FontFamily='Courier New' LevelText='o' NumberingFormat='Bullet' StartingIndex='1' />
<t:ListLevelStyle FontFamily='Wingdings' LevelText='?' NumberingFormat='Bullet' StartingIndex='1' />
<t:ListLevelStyle FontFamily='Symbol' LevelText='?' NumberingFormat='Bullet' StartingIndex='1' />
<t:ListLevelStyle FontFamily='Courier New' LevelText='o' NumberingFormat='Bullet' StartingIndex='1' />
<t:ListLevelStyle FontFamily='Wingdings' LevelText='?' NumberingFormat='Bullet' StartingIndex='1' />
<t:ListLevelStyle FontFamily='Symbol' LevelText='?' NumberingFormat='Bullet' StartingIndex='1' />
<t:ListLevelStyle FontFamily='Courier New' LevelText='o' NumberingFormat='Bullet' StartingIndex='1' />
<t:ListLevelStyle FontFamily='Wingdings' LevelText='?' NumberingFormat='Bullet' StartingIndex='1' />
</t:ListStyle>
<t:ListStyle ID='3'>
<t:ListLevelStyle LevelText='{}{0})' NumberingFormat='Decimal' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{1})' NumberingFormat='LowerLetter' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{2})' NumberingFormat='LowerRoman' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{3})' NumberingFormat='Decimal' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{4})' NumberingFormat='LowerLetter' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{5})' NumberingFormat='LowerRoman' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{6})' NumberingFormat='Decimal' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{7})' NumberingFormat='LowerLetter' StartingIndex='1' />
<t:ListLevelStyle LevelText='{}{8})' NumberingFormat='LowerRoman' StartingIndex='1' />
</t:ListStyle>
</t:RadDocument.ListStyles>
<t:Section>
<t:Paragraph>
<t:Paragraph.ListItemSerializationData>
<t:ListItemSerializationData ListID='1' ListLevel='0' />
</t:Paragraph.ListItemSerializationData>
<t:Span FontFamily='Verdana' FontSize='16' Text='sdfg sdfg sdfg' UnderlineColor='#FF000000' UnderlineDecoration='None' />
</t:Paragraph>
<t:Paragraph>
<t:Paragraph.ListItemSerializationData>
<t:ListItemSerializationData ListID='2' ListLevel='0' />
</t:Paragraph.ListItemSerializationData>
<t:Span FontFamily='Verdana' FontSize='16' Text='sdfgs' UnderlineColor='#FF000000' UnderlineDecoration='None' />
</t:Paragraph>
<t:Paragraph>
<t:Paragraph.ListItemSerializationData>
<t:ListItemSerializationData ListID='3' ListLevel='0' />
</t:Paragraph.ListItemSerializationData>
<t:Span FontFamily='Verdana' FontSize='16' Text='sdfg' UnderlineColor='#FF000000' UnderlineDecoration='None' />
</t:Paragraph>
</t:Section>
</t:RadDocument></tCtr:RadRichTextBox>";
var tb = (Telerik.Windows.Controls.RadRichTextBox)XamlReader.Load(radTextBoxXaml);
this.LayoutRoot.Children.Add(tb);
 
// after this method returns, the UI freezes

Below is the stack trace I obtained by Pausing my application in the Debugger and openning the "Debug->Windows->Threads" window

ThreadID = 2448
ManagedID = 1
Cagegory = Main Thread
Name = Main Thread
Priority = Normal
Location = Telerik.Windows.Documents.Model.Paragraph.FlowDirection.get()
            Telerik.Windows.Documents!Telerik.Windows.Documents.Model.Paragraph.FlowDirection.get() + 0x32 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.ParagraphLayoutBox.MeasureOverride.AnonymousMethod__0() + 0x74 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.ParagraphLayoutBox.MeasureOverride(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x1adf bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x557 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.LayoutElement.Measure(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x389 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverrideInternal(Telerik.Windows.Documents.Model.SizeF availableSize) + 0xa5d bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.SectionLayoutBox.MeasureOverride(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x11b bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x557 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.LayoutElement.Measure(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x389 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.DocumentLayoutBox.MeasureOverride(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x460 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.LayoutElement.MeasureCore(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x557 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Layout.LayoutElement.Measure(Telerik.Windows.Documents.Model.SizeF availableSize) + 0x389 bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.Model.RadDocument.Measure(Telerik.Windows.Documents.Model.SizeF measureSize) + 0x7e bytes 
            Telerik.Windows.Documents!Telerik.Windows.Documents.UI.DocumentWebLayoutPresenter.MeasureOverride(System.Windows.Size availableSize) + 0x378 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0xa3 bytes 
            [Managed to Native Transition] 
            System.Windows.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element, System.Windows.Size availableSize) + 0x62 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) + 0x18 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0xa3 bytes 
            [Managed to Native Transition] 
            System.Windows.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element, System.Windows.Size availableSize) + 0x62 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) + 0x18 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0xa3 bytes 
            [Managed to Native Transition] 
            System.Windows.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element, System.Windows.Size availableSize) + 0x62 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) + 0x18 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0xa3 bytes 
            [Managed to Native Transition] 
            System.Windows.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element, System.Windows.Size availableSize) + 0x62 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) + 0x18 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0xa3 bytes 
            [Managed to Native Transition] 
            System.Windows.dll!MS.Internal.XcpImports.FrameworkElement_MeasureOverride(System.Windows.FrameworkElement element, System.Windows.Size availableSize) + 0x62 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.Windows.Size availableSize) + 0x18 bytes 
            System.Windows.dll!System.Windows.FrameworkElement.MeasureOverride(System.IntPtr nativeTarget, float inWidth, float inHeight, out float outWidth, out float outHeight) + 0xa3 bytes 
            [Appdomain Transition] 

 

0
Iva Toteva
Telerik team
answered on 21 Sep 2011, 12:48 PM
Hello Rashad Rivera,

We are sorry to hear you are experiencing issues with RadRichTextBox. As for requesting code-samples and demos, we are only doing that as a last resort when we have not managed to reproduce the issue in a sample project of ours following the steps you have listed. It's all for the sake of resolving the problem you have encountered.

I am afraid you might not be happy about this answer either. I have tried the exact code you have posted with the latest version of the control and were not able to reproduce the UI freeze. Please find attached the application I have created.

The only possible cause that comes to mind (even though it is a long shot, provided that I could not reproduce the issue) is that you are using an older version of the controls or another version of Silverlight. You should have in mind that Silverlight 5 has not been officially released yet and is not supported for now.

Regards,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Rashad Rivera
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Jerrica
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Rashad Rivera
Top achievements
Rank 1
Share this question
or