Error CS0246: The type or namespace name `HtmlAgilityPack' could not be found

c# html-agility-pack namespaces

Question

I am currently working on a Natural Language processing program in which I am accessing Google Translate for my dictionary in order to translate the users input.

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

When I compile this program in Assembly, I am actually using Unity but it compiles with Assembly, I get the return error:

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?

I began to look up online the proper namespace for HtmlDocument, and read that I should write:

using HtmlAgilityPack;

After putting this into my program, I then received the error:

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?

I read online that I had to be more specific and use:

using HtmlAgilityPack.HtmlDocument;

Now that I put that in, I still continue to receive the error:

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?

I would like to know what namespace to use for HtmlDocument. Any help on this matter would be greatly appreciated!

Accepted Answer

Have you downloaded and referenced the HtmlAgilityPack dll? It seems like you're trying to use the (third-party) library without referencing it anywhere in your project/solution.

You can install the library using Nu-Get.

Install-Package HtmlAgilityPack


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why