【问题标题】:Error CS0246: The type or namespace name `HtmlAgilityPack' could not be found错误 CS0246:找不到类型或命名空间名称“HtmlAgilityPack”
【发布时间】:2012-09-25 17:11:47
【问题描述】:

我目前正在开发一个自然语言处理程序,在该程序中我正在访问 Google 翻译以获取我的字典,以便翻译用户的输入。

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;
    }
}

当我在Assembly中编译这个程序时,我实际上是在使用Unity,但是它使用Assembly编译,我得到了返回错误:

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 使用什么命名空间。非常感谢您对此事的任何帮助!

【问题讨论】:

  • 你导入了dll吗?比如,你记得在你的解决方案中添加了一个 dll 吗?
  • 您是否添加了对 HTML Agility Pack DLL 的引用?您应该考虑使用 NuGet 在您的项目中下载和安装 HAP!
  • 您是否添加了对正确 dll 的引用? stackoverflow.com/questions/846994/how-to-use-html-agility-pack
  • 不,我没有添加参考,谢谢!

标签: c# namespaces html-agility-pack


【解决方案1】:

您是否下载并引用了 HtmlAgilityPack dll?您似乎正在尝试使用(第三方)库而不在项目/解决方案中的任何地方引用它。

您可以使用 Nu-Get 安装库。

Install-Package HtmlAgilityPack

【讨论】:

    猜你喜欢
    • 2019-07-14
    • 2019-09-14
    • 2013-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-25
    相关资源
    最近更新 更多