Skip to content
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

ArgumentOutOfRangeException when calling "Render()" method #205

Open
Israel4Ever opened this issue Oct 28, 2015 · 1 comment
Open

ArgumentOutOfRangeException when calling "Render()" method #205

Israel4Ever opened this issue Oct 28, 2015 · 1 comment

Comments

@Israel4Ever
Copy link

Hi,
I'm getting this Exception while calling the "Render()" method:

System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Stack trace:

   at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at CsQuery.HtmlParser.HtmlData.TokenName(UInt16 tokenId)
   at CsQuery.Implementation.DomElement.get_ClassName()
   at CsQuery.Implementation.DomElement.d__38.MoveNext()
   at CsQuery.Output.FormatDefault.RenderElementInternal(IDomObject element, TextWriter writer, Boolean includeChildren)
   at CsQuery.Output.FormatDefault.RenderStack(TextWriter writer)
   at CsQuery.Output.FormatDefault.RenderChildren(IDomObject element, TextWriter writer)
   at CsQuery.Output.FormatDefault.Render(IDomObject node)
   at CsQuery.Implementation.DomObject.Render(IOutputFormatter formatter)
   at CsQuery.Implementation.DomObject.Render()
   at CsQuery.CQ.Render()
   at **** in ***:line 61

This is my code lines:

dom["style, script, and some more..."].Remove();
dom.Render(); // <---- BOOM

It's seems impossible to repro this issue. Tried few times with same URL.
Even when it's happen, I'm change the "next code line" (next instruction pointer) to the "Render()" code line agian - and now it's working.

My code is running with Multi-Threading. I'm pretty sure that this making problems...

How I can fix this?

Thank you.

lukasbob added a commit to Siteimprove/CsQuery that referenced this issue May 3, 2016
…mplemented in HtmlData.cs.

This addresses issues where the `nextID` counter overflows ushort.MaxValue and wraps around to return the wrong index value, resulting in wrong strings output from the `Render` method.

Fix jamietre#204, jamietre#205, jamietre#189, jamietre#164
@cn-ml
Copy link

cn-ml commented Apr 25, 2020

I got that error as well. Here is my stack trace if it helps.

Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
   at CsQuery.HtmlParser.HtmlData.TokenName(UInt16 tokenId)
   at CsQuery.Implementation.DomElement.get_ClassName()
   at CsQuery.Implementation.DomElement.<AttributesCollection>d__38.MoveNext()
   at CsQuery.Output.FormatDefault.RenderElementInternal(IDomObject element, TextWriter writer, Boolean includeChildren)
   at CsQuery.Output.FormatDefault.RenderStack(TextWriter writer)
   at CsQuery.Output.FormatDefault.Render(IDomObject node)
   at "myInternalCall CQ.Render()"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants