Description
so we sometimes get the following exception when run in a threaded environment... not sure why it matters but it only occurs when running within a thread:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at System.Collections.Generic.Dictionary2.Resize(Int32 newSize, Boolean forceNewHashCodes) at CsQuery.Implementation.DomDocument.AddToIndex(IDomIndexedNode element) in d:\projects\csharp\CsQuery\source\CsQuery\Dom\Implementation\DomDocument.cs:line 456 at CsQuery.Implementation.DomDocument.AddToIndex(IDomIndexedNode element) in d:\projects\csharp\CsQuery\source\CsQuery\Dom\Implementation\DomDocument.cs:line 465 at CsQuery.Implementation.DomDocument.AddToIndex(IDomIndexedNode element) in d:\projects\csharp\CsQuery\source\CsQuery\Dom\Implementation\DomDocument.cs:line 465 at CsQuery.Implementation.DomDocument.AddToIndex(IDomIndexedNode element) in d:\projects\csharp\CsQuery\source\CsQuery\Dom\Implementation\DomDocument.cs:line 465 at CsQuery.Implementation.DomDocument.AddToIndex(IDomIndexedNode element) in d:\projects\csharp\CsQuery\source\CsQuery\Dom\Implementation\DomDocument.cs:line 465 at CsQuery.Implementation.ChildNodeList.Reindex(Int32 index) in d:\projects\csharp\CsQuery\source\CsQuery\Dom\Implementation\ChildNodeList.cs:line 298 at CsQuery.Implementation.ChildNodeList.Remove(IDomObject item) in d:\projects\csharp\CsQuery\source\CsQuery\Dom\Implementation\ChildNodeList.cs:line 210 at System.Collections.Generic.List
1.ForEach(Action`1 action)
this occurs when calling:
var nodesToRemove = new List();
.... some code that creates the list goes here
nodesToRemove.ForEach(obj => obj.Remove());
that final line inside of it doing obj.remove()
is what causes the above exception and stack trace.
i think it has to do with threading and dictionarys not being thread safe.... even for adds
but i dont see how it matters.
whats stange is the same code works fine in our dev web server but our production one causes the exception.... it works fine in a console app but as soon as the code is thrown to run on a background thread it causes the above exception.