System.ArgumentOutOfRangeException was unhandled

Topics: User Forum
Jun 24, 2012 at 10:49 AM

Hello

I get the following but and I don't think I am doing anything wrong.

I create a new .net 4 console application in VS 2012 RC (clean machine, no other version of VS installed). I add a reference to HtmlAgilityPack and the code is just:

 

  Sub Main()
    Dim doc As New HtmlAgilityPack.HtmlDocument()
    Dim st = (New System.Net.WebClient).DownloadString("http://www.google.com/")
    doc.LoadHtml(st)
    Dim col = doc.DocumentNode.SelectNodes("//*")
  End Sub

This code breaks on SelectNodes. Interestingly it doesn break if I write a specific path "/html/body etc". But it does if the query stats with "//"

Charles

 

Full exception:

System.ArgumentOutOfRangeException was unhandled  HResult=-2146233086  Message=Index was out of range. Must be non-negative and less than the size of the collection.Parameter name: index  ParamName=index  Source=HtmlAgilityPack  StackTrace:       at HtmlAgilityPack.HtmlNodeNavigator.MoveToFirstChild()       at MS.Internal.Xml.XPath.XPathDescendantIterator.MoveNext()       at MS.Internal.Xml.XPath.DescendantQuery.Advance()       at MS.Internal.Xml.XPath.XPathSelectionIterator.MoveNext()       at HtmlAgilityPack.HtmlNode.SelectNodes(String xpath)       at testHTMLAP.Module1.Main() in C:\Data\Programming\vb\tmp\testHTMLAP\testHTMLAP\Module1.vb:line 7       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)       at System.Threading.ThreadHelper.ThreadStart()  InnerException: 

Jun 24, 2012 at 8:05 PM

Apparently it was a conflict with another version installed on the machine by a third party component