Unplanned
Last Updated: 26 Dec 2022 10:29 by ADMIN
Prashant
Created on: 16 Dec 2022 14:45
Category: RichTextEditor
Type: Bug Report
6
RadRichTextEditor: System.StackOverflowException when exporting with HtmlFormatProvider

Use the code below.

1. Click the first button to insert a link.

2. Click inside the link to move the cursor.

3. Click the second button to insert the yellow rectangle

4. Click the third button to export the HTML content.

Actual result: StackOverflow exception occurs

        private void radButton1_Click(object sender, EventArgs e)
        {
            HyperlinkInfo info = new HyperlinkInfo()
            {
                NavigateUri = "http://www.google.com",
                Target = HyperlinkTargets.Blank,
                IsAnchor = false
            };
            this.radRichTextEditor1.InsertHyperlink(info, "www.google.com");
        }

        private void radButton2_Click(object sender, EventArgs e)
        {
            LightVisualElement button = new LightVisualElement();
            button.Text = "My Button";
            button.DrawFill = true;
            button.BackColor = System.Drawing.Color.Yellow;
            button.GradientStyle = Telerik.WinControls.GradientStyles.Solid;

            Section section = new Section();
            Paragraph paragraph = new Paragraph();
            InlineUIContainer container = new InlineUIContainer();
            RadElementUIContainer radContainer = new RadElementUIContainer(button);
            container.UiElement = radContainer;
            container.Height = 25;
            container.Width = 70;
            paragraph.Inlines.Add(container);
            section.Blocks.Add(paragraph);
            RadDocument doc = new RadDocument();
            doc.Sections.Add(section);
            radRichTextEditor1.InsertFragment(new DocumentFragment(doc));
        }

        private void radButton3_Click(object sender, EventArgs e)
        {
            Telerik.WinForms.Documents.Model.RadDocument document = radRichTextEditor1.Document;

            Telerik.WinForms.Documents.FormatProviders.Html.HtmlFormatProvider provider = new Telerik.WinForms.Documents.FormatProviders.Html.HtmlFormatProvider();

            provider.ExportSettings.InlineUIContainerExporting += ExportSettings_InlineUIContainerExporting;

            provider.ExportSettings.DocumentExportLevel = Telerik.WinForms.Documents.FormatProviders.Html.DocumentExportLevel.Fragment;
            provider.ExportSettings.ExportFontStylesAsTags = true;
            provider.ExportSettings.SpanExportMode = Telerik.WinForms.Documents.FormatProviders.Html.SpanExportMode.DefaultBehavior;
            string htmlValue = provider.Export(document);
            webBrowser1.DocumentText = htmlValue;
        }

        private void ExportSettings_InlineUIContainerExporting(object sender, Telerik.WinForms.Documents.FormatProviders.Html.InlineUIContainerExportingEventArgs e)
        { 
        }

Attached Files:
3 comments
ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 26 Dec 2022 10:29
Hello, Prashant,     

We will do our best to introduce a stable fix in the upcoming releases. Please excuse us for the inconvenience caused. 

Currently, the possible solution that I can suggest is to prevent inserting an inline container when the caret is positioned in the middle of a hyperlink. A sample approach is demonstrated here:
        private void radButton2_Click(object sender, EventArgs e)
        {
            Inline inline = this.radRichTextEditor1.Document.CaretPosition.GetCurrentInline();

            IHyperlinkRangeMarker hyperlink = inline.FieldStart as IHyperlinkRangeMarker;
            if (hyperlink != null)
            {
                return;
                // The caret position is inside a hyperlink
            }

            LightVisualElement button = new LightVisualElement();
            button.Text = "My Button";
            button.DrawFill = true;
            button.BackColor = System.Drawing.Color.Yellow;
            button.GradientStyle = Telerik.WinControls.GradientStyles.Solid;

            Section section = new Section();
            Paragraph paragraph = new Paragraph();
            InlineUIContainer container = new InlineUIContainer();
            RadElementUIContainer radContainer = new RadElementUIContainer(button);
            container.UiElement = radContainer;
            container.Height = 25;
            container.Width = 70;
            paragraph.Inlines.Add(container);
            section.Blocks.Add(paragraph);
            RadDocument doc = new RadDocument();
            doc.Sections.Add(section);
            radRichTextEditor1.InsertFragment(new DocumentFragment(doc));
        }

Please give it a try and see how it works on your end.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Prashant
Posted on: 20 Dec 2022 10:07

Hello Dess,

 

Please provide me some solution as soon as possible as this issue breaks my application. 

So I need at least some solution to save my application to be killed in middle of my work.

Hoping for faster reply.

 

Thanks,

Prashant.

ADMIN
Dess | Tech Support Engineer, Principal
Posted on: 16 Dec 2022 14:51

Hello, Prashant,

Thank you for bringing this to our attention.

Due to the specificity of the issue I am unable to suggest a suitable solution. We will do our best to address this issue accordingly. Make sure that you follow this item in order to get notified once any status changes occured.

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.