Hi
i am creating readonly ranges using the InsertReadOnlyRange method.
This works well most of the times.
However I get a NullReferenceException deeply from the tk-lib code
with the following stacktrace:
the line raising the exception goes like:
"Parent" is null here.
I noticed that the "null-ness" and the exception only occur if the span is inserted using InsertInline:
so my wish to the telerik developpers is to fix this line of code.
There are circumstances where a spanbox has no Parent layoutbox.
(E.g. when appending it with InsertInline). So you can't use it to get its previous sibling.
If you anaylze the stack trace and the surrounding code of "GetCaretInline"
it's fully OK to null check the Parent property and in this case simply return
the span associated to the layoutbox "currentSpanBox".
Chris
i am creating readonly ranges using the InsertReadOnlyRange method.
This works well most of the times.
However I get a NullReferenceException deeply from the tk-lib code
with the following stacktrace:
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.Model.RadDocument.GetCaretInline() Line 1319 C#
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.Model.RadDocument.GetCurrentSpanStyle() Line 1336 + 0xc bytes C#
Telerik.Windows.Documents.dll!Telerik.Windows.Controls.RadRichTextBox.UpdateCurrentStyles() Line 2974 + 0x20 bytes C#
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.UI.DocumentWebLayoutPresenter.DoOnCaretLocationChanged() Line 441 C#
Telerik.Windows.Documents.dll!Telerik.Windows.Documents.UI.DocumentWebLayoutPresenter.DoOnDocumentChanged.AnonymousMethod__6() Line 409 + 0xa bytes C#
the line raising the exception goes like:
//Line 1319 in RadDocument.cs
SpanLayoutBox previousSpanBox = DocumentStructureCollection.GetPreviousSiblingForDocumentElement(currentSpanBox,
currentSpanBox.Parent.AssociatedDocumentElement)
as
SpanLayoutBox;
// ^^^^^NullReferenceException: Parent is null sometimes
"Parent" is null here.
I noticed that the "null-ness" and the exception only occur if the span is inserted using InsertInline:
RadDocument doc = editor.Document;
var span1 =
new
Span(
"This text is protected"
);
// doc.InsertInline(span1); //this span's spanbox will have no Parent, causing a Null ref
(doc.Sections.Last.Blocks.Last
as
Paragraph).Inlines.Add(span1);
//this span's spanbox will have a Parent, not causing a Null ref
DocumentPosition pos3 =
new
DocumentPosition(doc.DocumentLayoutBox,
true
);
var spb1 = span1.FirstLayoutBox
as
SpanLayoutBox;
pos3.MoveToInline(spb1, 0);
DocumentPosition pos4 =
new
DocumentPosition(doc.DocumentLayoutBox,
true
);
pos4.MoveToInline(spb1, spb1.PositionsCountInBox - 1);
doc.InsertReadOnlyRange(pos3, pos4);
// raises Null ref in RadDocument.GetCaretInline if using "doc.InsertInline"
so my wish to the telerik developpers is to fix this line of code.
There are circumstances where a spanbox has no Parent layoutbox.
(E.g. when appending it with InsertInline). So you can't use it to get its previous sibling.
If you anaylze the stack trace and the surrounding code of "GetCaretInline"
it's fully OK to null check the Parent property and in this case simply return
the span associated to the layoutbox "currentSpanBox".
Chris