2011-11-10 85 views
-1

我能夠在一個控制檯應用程序使用HtmlAgilityPack,但在一個WPF應用程序嘗試時,我總是在這條線document.DocumentNode.Descendants()此錯誤:HtmlAgilityPack不工作對我的WPF項目

Could not find an implementation of the query pattern for source type 'System.Collections.Generic.IEnumerable<HtmlAgilityPack.HtmlNode>'. 'Where' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'? 

這是代碼:

public partial class Window1 : Window 
    { 
     public Window1() 
     { 
      var webget = new HtmlWeb(); 

      var document = webget.Load("http://google.com"); 

      var p = from program in document.DocumentNode.Descendants() 
        where program.Name == "a" 
        select program.InnerText; 

      InitializeComponent(); 
     } 
    } 

任何人都有一個idee爲什麼我得到那個錯誤?

謝謝。

+1

但是你有一個在該源文件中使用System.Linq? – ordag

+0

達姆,我很慚愧,請張貼它作爲答案,我會接受,謝謝。 – Kobe

回答

3

地址:

using System.Linq; 

到您的現有使用語句附近的文件的頂部。

2

添加命名空間聲明System.Linq

using System.Linq; 
1

你必須添加名稱空間編寫這些代碼...

var p = from program in document.DocumentNode.Descendants() 
       where program.Name == "a" 
       select program.InnerText; 

這是使用LINQ寫的,所以你必須添加using System.Linq;這個命名空間