Stack Overflow exception

Topics: Developer Forum, User Forum
May 14, 2010 at 1:06 PM

Hey ,

I ve got an exception caused by overflow of stack on the function HtmlDocument.save(),

What i was doing, I was trying to parse an html file, loaded that html in my HtmlDocument and chnaged some elements ids and added some attributes,
after that when i tried to save all my work done , i got stack overflow ,

here is the code

{
HtmlAgilityPack.HtmlDocument HtmlDoc = new HtmlDocument();
HtmlDoc.LoadHtml(MyHtmlString);
IEnumerable<HtmlNode> tempCollection1 = HtmlDoc.DocumentNode.Descendants("body");
IEnumerable<HtmlNode> tempCollection = tempCollection1.First().DescendantNodes();

foreach ( HtmlNode tagElement in tempCollection )
{
///
/// I Made Some Changes
/// Like change id value / bind some events
///
}

//Following line throws exception
HtmlDoc.Save(@"C:\index2.html");

}


I want to know if that is any bug or am I doing something wrong

May 14, 2010 at 1:12 PM

Can you send the actual stack overflow exception, stacktrace and location of where it was thrown?

May 14, 2010 at 1:24 PM
Edited May 14, 2010 at 2:00 PM

Here is the stack trace.

what i found is this that when  i changed html element attribute value , exception did not occured,

like...

tagElement.Attributes["attributeName"].Value = "AnyValue";

but when i added some attribute like

<font size="2">

tagElement.Attributes.Add("onmouseover", "MyJSFunc(this)");

And tried to save, exception comes

 

 

 

> HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1744 + 0xa bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {System.IO.StringWriter}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {System.IO.StringWriter}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {System.IO.StringWriter}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#

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

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

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

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

 

> HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo() Line 1746 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.OuterHtml.get() Line 488 + 0xe bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlTextNode.Text.get() Line 60 + 0x8 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {System.IO.StreamWriter}) Line 1572 + 0x2f bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteContentTo(System.IO.TextWriter outText = {System.IO.StreamWriter}) Line 1494 + 0xd bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {System.IO.StreamWriter}) Line 1673 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteContentTo(System.IO.TextWriter outText = {System.IO.StreamWriter}) Line 1494 + 0xd bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {System.IO.StreamWriter}) Line 1673 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteContentTo(System.IO.TextWriter outText = {System.IO.StreamWriter}) Line 1494 + 0xd bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlNode.WriteTo(System.IO.TextWriter outText = {System.IO.StreamWriter}) Line 1568 + 0xb bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlDocument.Save(System.IO.TextWriter writer = {System.IO.StreamWriter}) Line 899 + 0x18 bytes C#
  HtmlAgilityPack.DLL!HtmlAgilityPack.HtmlDocument.Save(System.IO.StreamWriter writer = {System.IO.StreamWriter}) Line 886 + 0xb bytes C#
  App_Web_mtodxfh8.dll!_Default.Page_Load(object sender = {ASP.default_aspx}, System.EventArgs e = {System.EventArgs}) Line 62 + 0xd bytes C#
  [External Code] 

 

 

 

 

 

Sep 17, 2010 at 8:28 AM

Hi,

I'm getting the exact same error, is there a fix or workaround for this at all?

Thanks

 

Dan

Oct 5, 2010 at 11:33 PM

Hello,

I did a quick workaround for this:

http://devva.net/blog/post/Workaround-for-the-HtmlAgilityPack-StackOverflowException-bug.aspx