This project has moved and is read-only. For the latest updates, please go here.

StackOverflow when accessing the OuterHtml property.


When an HtmlNode is of NodeType Text, and an operation happens that changes the OuterHtml there's going to be a StackOverflow whenever the OuterHtml is accessed again.

The reason is, in the HtmlTextNode class, the call to the OuterHtml property of the base class inside the getter of the Text property when the _outerchanged field is set to true and the _text field hasn't been accessed will cause a StackOverflowException.

A simple example is calling RemoveAll() over a Text node's HtmlAttributeCollection and then accessing the OuterHtml property, like this.
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml("This is a text node");

HtmlNode textNode = doc.DocumentNode.ChildNodes[0];
textNode.Attributes.RemoveAll();       // Any operation that will set the _outerchanged field to true
string text = textNode.OuterHtml;     // StackOverflowException is thrown.


elendil326 wrote Aug 14, 2014 at 5:39 PM

Solution in patch mentioned in issue

wrote Aug 14, 2014 at 5:43 PM