-
-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stackoverflow when using ReplaceChild #513
Comments
Hello @enkelmedia , Thank you for the project. My developer will look at it. Best Regards, Jon Sponsorship Performance Libraries Runtime Evaluation |
Hello @enkelmedia , A custom exception pointing to this issue has been added in the v1.11.53 The issue was caused because the html-agility-pack/src/HtmlAgilityPack.Shared/HtmlNode.cs Lines 1003 to 1016 in 7c35d8f
Another way to make it work is to clone the current node that you want to replace and use it: if (tables != null && tables.Any())
{
foreach (var table in tables)
{
var nestedTable = table.Clone();
// Wrap the table in a div "table-wrapper" so that we can apply "mobile table"-css.
var wrapperDivNode = HtmlNode.CreateNode("<div class=\"table-wrapper\"></div>");
wrapperDivNode.ChildNodes.Add(nestedTable);
table.ParentNode.ReplaceChild(wrapperDivNode, table);
}
} Let me know if everything is fine for you or there is something else related to this issue. Best Regards, Jon Are you finding this library useful? If so, please consider supporting its continued development by becoming a sponsor. Additionally, if you think your enterprise would benefit from this library, we encourage you to suggest they become a sponsor as well. Your support will help ensure this library remains alive and well-supported. |
I just upgraded the dependency on html-agility-pack from an older version to
1.11.52
and suddenly started to get Stack overflow exceptions.1. Description
The problem happens in a couple of areas that I have identified.
Using ReplaceChild (when replaced node has already been added to something else)
(details below)
and:
The workaround here was to just iterate a new list and remove:
There is a sample of the problem:
2. Exception
Could not get a good stack trace because of the stack overflow.
3. Fiddle or Project
Error:
https://dotnetfiddle.net/YJJ2jq
Moving the "ReplaceChild" before the "ChildNodes.Add" makes it work:
https://dotnetfiddle.net/sJCUmN
This used to work in older versions and it might be fair that it does not work but there should be a better exception and not a stack overflow.
Works:
4. Any further technical details
Add any relevant detail can help us, such as:
The text was updated successfully, but these errors were encountered: