2012-09-25 297 views
4

我目前正在研究自然語言處理程序,在該程序中,我正在訪問Google翻譯以查找我的字典以翻譯用戶輸入。錯誤CS0246:找不到類型或名稱空間名稱`HtmlAgilityPack'

using UnityEngine; 
using System.Collections; 
using System.Text; 
using System.Net; 
public class GoogleTranslate : MonoBehaviour { 
    public static string Translate(string input, string languagePair, Encoding encoding) 
    { 
     string url = String.Format("http://www.google.com/translate_t?hl=en&ie=UTF8&text=  {0}&langpair={1}", input, languagePair); 
     string result = String.Empty; 

     using (WebClient webClient = new WebClient()) 
     { 
      webClient.E ncoding = encoding; 
      result = webClient.DownloadString(url); 
     } 

     HtmlDocument doc = new HtmlDocument(); 
     doc.LoadHtml(result); 
     return doc.DocumentNode.SelectSingleNode("//textarea[@name='utrans']").InnerText; 
    } 
} 

當我編譯這個程序彙編,我實際上使用Unity但它與大會編譯,我得到的回報錯誤:

Assets/GoogleTranslate.cs(17,13): error CS0246: The type or namespace name `HtmlDocument' could not be found. Are you missing a using directive or an assembly reference? 

我就開始在網上查找正確的命名空間的HTMLDocument和閱讀,我應該寫:

using HtmlAgilityPack; 

把這個變成我的計劃後,我便收到錯誤:

Assets/GoogleTranslate.cs(5,7): error CS0246: The type or namespace name `HtmlAgilityPack' could not be found. Are you missing a using directive or an assembly reference? 

我在網上看了,我不得不更加具體和使用:

using HtmlAgilityPack.HtmlDocument; 

現在,我把在,我還是繼續收到錯誤:

Assets/GoogleTranslate.cs(5,7): error CS0246: The type or namespace name `HtmlAgilityPack' could not be found. Are you missing a using directive or an assembly reference? 

我想了解HtmlDocument使用的命名空間。任何關於此事的幫助將不勝感激!

+1

你導入了dll嗎?像,你記得添加一個DLL到你的解決方案? – Thousand

+0

您是否添加了對HTML敏捷包DLL的引用?您應該考慮使用NuGet在您的項目中下載並安裝HAP! – Zachary

+0

您是否添加了對正確dll的引用? http://stackoverflow.com/questions/846994/how-to-use-html-agility-pack –

回答

1

您是否下載並引用了HtmlAgilityPack dll?看起來您正嘗試使用(第三方)庫,而無需在項目/解決方案中的任何地方引用它。

您可以使用Nu-Get安裝庫。

Install-Package HtmlAgilityPack 
+0

感謝您的幫助! –

相關問題