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 on multithreading #204

Open
Israel4Ever opened this issue Oct 28, 2015 · 0 comments
Open

ArgumentOutOfRangeException on multithreading #204

Israel4Ever opened this issue Oct 28, 2015 · 0 comments

Comments

@Israel4Ever
Copy link

Hi,
I'm running my code that working with CsQuery and getting this exception:

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

Call stack:

   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.d__f.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at CsQuery.Implementation.DomElement.SetClassName(String className)
   at CsQuery.Implementation.DomElement.set_ClassName(String value)
   at CsQuery.Implementation.DomElement.SetAttribute(UInt16 tokenId, String value)
   at CsQuery.Implementation.DomElement.SetAttribute(String name, String value)
   at CsQuery.HtmlParser.CsQueryTreeBuilder.CreateElement(String ns, String name, HtmlAttributes attributes)
   at HtmlParserSharp.Core.TreeBuilder`1.AppendToCurrentNodeAndPushElement(ElementName elementName, HtmlAttributes attributes)
   at HtmlParserSharp.Core.TreeBuilder`1.AppendToCurrentNodeAndPushBodyElement(HtmlAttributes attributes)
   at HtmlParserSharp.Core.TreeBuilder`1.StartTag(ElementName elementName, HtmlAttributes attributes, Boolean selfClosing)
   at HtmlParserSharp.Core.Tokenizer.EmitCurrentTagToken(Boolean selfClosing, Int32 pos)
   at HtmlParserSharp.Core.Tokenizer.StateLoop(Int32 state, Char c, Int32 pos, Char[] buf, Boolean reconsume, Int32 returnState, Int32 endPos)
   at HtmlParserSharp.Core.Tokenizer.TokenizeBuffer(UTF16Buffer buffer)
   at CsQuery.HtmlParser.ElementFactory.Tokenize()
   at CsQuery.HtmlParser.ElementFactory.Parse(Stream inputStream, Encoding encoding)
   at CsQuery.HtmlParser.ElementFactory.Create(Stream html, Encoding streamEncoding, HtmlParsingMode parsingMode, HtmlParsingOptions parsingOptions, DocType docType)
   at CsQuery.Implementation.DomDocument.Create(Stream html, Encoding encoding, HtmlParsingMode parsingMode, HtmlParsingOptions parsingOptions, DocType docType)
   at CsQuery.CQ.CreateNew(CQ target, Stream html, Encoding encoding, HtmlParsingMode parsingMode, HtmlParsingOptions parsingOptions, DocType docType)
   at CsQuery.CQ..ctor(Stream html, Encoding encoding, HtmlParsingMode parsingMode, HtmlParsingOptions parsingOptions, DocType docType)
   at CsQuery.CQ.Create(Stream html, Encoding encoding, HtmlParsingMode parsingMode, HtmlParsingOptions parsingOptions, DocType docType)
   at ***.<>c__DisplayClass6_0.b__0() in ****:line 133

My working flow is:

  1. I'm downloading URL into local file.
  2. Calling Create() method to load this file into CQ object. Like this:
dom = CQ.Create(
    StreamToFile,
    encoding,
    HtmlParsingMode.Auto,
    HtmlParsingOptions.IgnoreComments
);

When I running same URL agian, this is pass successfuly without any exception. So I'm guess that this depends on some multi-threading conditions.

CsQuery version: v1.3.4 (latest via Nu-Get)
.Net framework: v4.5.1
Visual studio 2015

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
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

1 participant