StackOverflowException when inserting section break after a paragraph

3 posts, 0 answers
  1. Jack
    Jack avatar
    4 posts
    Member since:
    Aug 2012

    Posted 09 Dec 2012 Link to this post

    I keep getting this error when inserting a section break after a paragraph.I tagged the document element where i wanted to add section break.

     var taggedElements = documentElements.Where(e => e.Tag == "SectionBreak");

                    IList<DocumentPosition> breaks = new List<DocumentPosition>();

                    if (taggedElements.Count() > 0)
                        foreach (DocumentElement element in taggedElements)
                            var inlineBox = element.FirstLayoutBox as ParagraphLayoutBox;
                            InlineLayoutBox inline = inlineBox.ChildLayoutBoxes.First as InlineLayoutBox;

                    foreach (DocumentPosition pos in breaks)
                        MyRadDocument.InsertSectionBreak(pos, MyRadDocument.Style, Telerik.Windows.Documents.SectionBreakType.NextPage);

    Any ideas?

  2. Petya
    Petya avatar
    973 posts

    Posted 12 Dec 2012 Link to this post

    Hello Jack,

    I tested this case and was unable to reproduce a StackOverflowException. However, I observe some inconsistent behavior on our end when more than one tagged element is present in the document.

    When you add the elements in your breaks collection all positions are as should be. However, once you perform the first insertion of a section break, all sequential positions point to the wrong place, which is expected. 

    Also, though the method you choose for inserting a section break works, the Undo command cannot be used to reverse each inserted break. In order to preserve the history, you should use a method of the editor instead.

    I have modified the above code to use the editor method and avoided traversing the layout boxes of the document in the process as that too may cause issues. In addition, I was able to implement the method with one foreach cycle, so it should also perform better.
    RadDocument MyRadDocument = this.editor.Document;
    var documentElements = MyRadDocument.EnumerateChildrenOfType<Paragraph>();
    var taggedElements = documentElements.Where(e => e.Tag == "SectionBreak").ToList();
    foreach (Paragraph paragraph in taggedElements)

    I hope this will be helpful. Let us know how it goes and if you are still experiencing issues get back to us with additional details (stack trace, etc.).

    All the best,
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Jack
    Jack avatar
    4 posts
    Member since:
    Aug 2012

    Posted 16 Dec 2012 Link to this post

    Thanks much.

    Was able to use this approach..
Back to Top