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

[Solved] System.OutOfMemoryException

0 Answers 116 Views
Editor
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
ori
Top achievements
Rank 1
ori asked on 03 Feb 2011, 05:38 PM
Hi to all

I am having a problem of  loading data from the database back into the form.
I am getting "System.OutOfMemoryException" exeption.

The exception occurs while i am decoding the html.
var htmlContent = HttpUtility.HtmlDecode(content.Text);
content.Text = htmlContent.IndentHtml();

In the file StringExtensions.cs, class "StringExtensions" we have the methode called "public static string IndentTags(this string html)".
In the lines:
while (token.Length > WRAP_THRESHOLD)
 {
         int splitPoint = token.Substring(0, WRAP_THRESHOLD).LastIndexOf(' ');
         result.Append(token.Substring(0, splitPoint)).Append(newLine.PadRight(newLineLength + indentSize * (indentLevel + 1)));
         token = token.Substring(splitPoint);
}
I can see that the code doesn't go out of the loop, therefore i am getting  "OutOfMemoryException" exception.

you can test it yourself with the next html code:
<p dir="RTL" style="margin-top:0cm;margin-right:4.2pt;margin-bottom:3.75pt;margin-left:0cm;text-align:justify;line-height:13.5pt;direction:rtl;unicode-bidi:embed;"><span lang="nl" style="font-family:"Tahoma","sans-serif";color:black;">gaz

Probably this html was generated in word document, Is there a way to clean HTML code that users pasted from word document ?
can i ask, why the WRAP_THRESHOLD is set to 120 ?
private const int WRAP_THRESHOLD = 120;

I can add an if statement that checks the "splitPoint" if its 0 the we need to brake the loop, or something like that.

Any advice will be appreciated

 Thank you

Ori
Tags
Editor
Asked by
ori
Top achievements
Rank 1
Share this question
or