1

我无计可施。每当我尝试使用 XPath 选择节点时,我都会不断收到 HtmlAgilityPack 异常。即使我只用这个例子开始一个全新的解决方案,问题仍然存在(所以我的应用程序代码以某种方式干扰不是问题。网页没有问题,或者我的互联网连接或类似的东西。我知道我有这以前工作过。我什至怀疑某个损坏的 dll 不知何故并重新下载了它,但无济于事。有什么想法吗?

using System;
using HtmlAgilityPack;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var web = new HtmlWeb();
            var doc = web.Load("http://www.google.com");
            var root = doc.DocumentNode;

            var links = root.SelectNodes("//a");
            // Error!  ArgumentOutOfRangeException: Index was out of range. 
            // Must be non-negative and less than the size of the collection.
        }
    }
}

/*
    System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
       at System.ThrowHelper.ThrowArgumentOutOfRangeException()
       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 ConsoleApplication1.Program.Main(String[] args) 

*/

编辑:

嗯...我不确定它是如何发生的或它做了什么,但我发现 .dll 安装在 GAC_MSIL 文件夹中。删除它立即解决了问题。所以,没关系!

4

0 回答 0