Under Review
Last Updated: 23 Jan 2025 12:37 by ADMIN
Prashant
Created on: 23 Jan 2025 07:18
Category: UI for WinForms
Type: Bug Report
0
RadRichTextEditor: System.StackOverflowException when exporting with HtmlFormatProvider

Hello there,

I am facing system.StackOverflowExcepiton while exporting document with HtmlFormatProvider. I am attaching my code with the HTML string which I am passing into RichTextEditor.

---------------------------------------------------------

HTML String:

"Navigate to the <a href="https://exelon.ifs.cloud/landing-page/" target="_blank"><b><u>IFS Cloud Landing Page</u></b></a>.<br /> <br />NOTE: If the above link does not work for you, copy and paste this address ...<br /> <br /><u>https://exelon.ifs.cloud/landing-page/</u>"

---------------------------------------------------------

Method which is giving me an error:

               

internal static string GetRadRichTextEditorHtmlValue(RadRichTextEditor radRichTextEditor, bool RemoveNewLineSpace = false, bool withDocumentChange = true, bool removeLastParagraphLine = false, bool fromDefinationEditor = false, bool OnlyHtml = false, bool fromDynamicAssetDefinition = false)
        //internal static string GetRadRichTextEditorHtmlValue(RadRichTextEditor radRichTextEditor, bool RemoveNewLineSpace = false, bool withDocumentChange = true, bool removeLastParagraphLine = false, bool fromDefinationEditor = false,bool OnlyHtml=false)
        {
            string htmlValue = string.Empty;

            try
            {
                if (radRichTextEditor == null)
                    return "";

                Telerik.WinForms.Documents.Model.RadDocument document = radRichTextEditor.Document;
                Telerik.WinForms.Documents.FormatProviders.Html.HtmlFormatProvider provider = new Telerik.WinForms.Documents.FormatProviders.Html.HtmlFormatProvider();
                if (withDocumentChange)
                {
                    //Telerik.WinForms.Documents.FormatProviders.Html.HtmlExportSettings htmlExportSettings = new Telerik.WinForms.Documents.FormatProviders.Html.HtmlExportSettings();
                    //htmlExportSettings.ExportHeadingsAsTags = true;
                    //provider.ExportSettings = htmlExportSettings;
                    //htmlExportSettings.PropertiesToIgnore["h1"].Add("Heading1");
                    provider.ExportSettings.DocumentExportLevel = Telerik.WinForms.Documents.FormatProviders.Html.DocumentExportLevel.Fragment;
                    provider.ExportSettings.ExportFontStylesAsTags = true;
                }
htmlValue = provider.Export(document); // Exception place.
                if (withDocumentChange)
                {
                    string strikeClassName = GetStrikeClassName(htmlValue);
                    htmlValue = GetTagValueFromHtmlString(htmlValue, fromDefinationEditor, fromDynamicAssetDefinition);
                    htmlValue = StripHtmlExceptFontTags(htmlValue, strikeClassName, RemoveNewLineSpace, OnlyHtml);
                }
                document.Dispose();
            }
            catch (Exception ex)
            {
                ClickLearn.Exceptions.ExceptionToEventLog(ex, "GetRadRichTextEditorHtmlValue");
            }

            // TO DO: Remove below condition when <br/> issue fixed fom editor
            if (htmlValue.IndexOf("<br />") == 0 || htmlValue.IndexOf("</ br>") == 0)
            {
                htmlValue = htmlValue.Substring(6);
            }
            else if (htmlValue.IndexOf("<br/>") == 0 || htmlValue.IndexOf("</br>") == 0)
            {
                htmlValue = htmlValue.Substring(5);
            }

            if (!string.IsNullOrEmpty(htmlValue))
            {
                htmlValue = RemoveLastNewLine(htmlValue);
            }

            return htmlValue;
        }

---------------------------------------------------------

Control's properties:

ucRichTextBox ucRichTextBox2 = new ucRichTextBox(tagCommand.Tags, ce.CurrentLCID, true, MetadataProperties, ArgInfoList);
ucRichTextBox2.spd = spd;
ucRichTextBox2.Tag = tagCommand.Tags;
ucRichTextBox2.Name = "ucRichTextBox2";
ucRichTextBox2.Left = sx;
ucRichTextBox2.Top = y;
ucRichTextBox2.Width = pnlSPD.Width - leftPadding - rightPadding;
ucRichTextBox2.btnUnlock.Click += BtnUnlock_Click;
ucRichTextBox2.btnUnlock.Image = Properties.Resources.c_full;
ucRichTextBox2.btnUnlock.Tag = "c_full";
ucRichTextBox2.btnLockOption.Visible = true;
ucRichTextBox2.btnLockOption.BringToFront();
ucRichTextBox2.btnLockOption.MouseDown += BtnLockOption_MouseDown;
ucRichTextBox2.btnLink.Click += BtnLink_Click;
ucRichTextBox2.rtxContent.CommandExecuting += RtxContent_CommandExecuting;
ucRichTextBox2.btnSetting.ButtonElement.ToolTipText = argInfoUX12.ConfigDoc.ContainsKey

---------------------------------------------------------

UI for the control:

---------------------------------------------------------

Error message:

 

1 comment
ADMIN
Dinko | Tech Support Engineer
Posted on: 23 Jan 2025 12:37

Hi Prashant,

The provided details are greatly appreciated. 

To confirm the Feedback Item I will need first to isolate this exception in a standalone project. I tried to follow your steps but so far no exception has been raised on my side. You can find my test project attached to this reply. Can you check my project and see if this exception is raised on your side? Keep in mind that I have tested the project with the latest version of our assemblies. From the ticket options, I see that you are using an older version of our controls. I would recommend downloading the latest version of our controls and test again if this exception is raised again.

In addition, I noticed that a similar behavior was logged from your account: RadRichTextEditor: System.StackOverflowException when exporting with HtmlFormatProvider. The same exception is thrown, however, I am not sure if the steps are similar to the one reported here. May I ask you to check it again and if they are the same, post the new steps in the old item to raise its priority.

Regards,
Dinko | Tech Support Engineer
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.

Attached Files: