1

I am working on a language translation program where I get information from offline. I am using Unity game engine, which uses Assembly as its IDE. Below is my code so far.

class Dictionary
{
    public 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.Encoding = encoding;
            result = webClient.DownloadString(url);
        }

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

However, when compiling, I receive the error:

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

I began doing research and heard that HtmlAgilityPack was a third-party software, and that I had to reference the .dll. I downloaded VisualStudio2010, as well as NuGet. Inside of Visual Studio I clicked "Manage NuGet Packages" and installed the HtmlAgilityPack. Inside of Visual Studio the error went away, however when I tried to open the file in Assembly, I still receive the error that the namespace HtmlAgilityPack could not be found. I am using Unity game engine, so I have to take the file from the VisualStudio file and place it in a different folder. Is there some step that I am missing, or do I need to do something in assembly to reference the HtmlAgilityPack dll? Any help would be greatly appreciated.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
Cameron Barge
  • 309
  • 2
  • 6
  • 17

4 Answers4

2

After referencing the HtmlAgilityPakc.dll like Austin and Shakir said, I still could not get the error to work. I fixed this error by not only referencing the HtmlAgilityPack.dll, but also placing the HtmlAgilityPack.dll in the folder with my script. This got rid of the error. Thanks for all of your help!

Cameron Barge
  • 309
  • 2
  • 6
  • 17
1

Try adding the HTMLAgility from the Add References tab!

SHAKIR SHABBIR
  • 1,295
  • 1
  • 14
  • 25
  • I clicked edit references and added the HtmlAgilityPack.dll, but it still comes up with the error namespace "HtmlAgilityPack" could not be found. Do you have anyother ideas as to how to fix this? – Cameron Barge Oct 11 '12 at 19:01
  • If you are using any Webcontrol that's associated with the assembly, then on the .aspx page, add the following line at the start of the page code: <%@ Register Assembly="HtmlAgilityPack" Namespace="HtmlAgilityPack" TagPrefix="htmlagl" %> If this works, it will be great – SHAKIR SHABBIR Oct 12 '12 at 07:27
1

Under the project, go to Add References and ensure that HTMLAgilityPack has been added. Since you already have using HtmlAgilityPack;, it should be fixed.

Your other question on this topic should solve this too.

Community
  • 1
  • 1
Austin Henley
  • 4,625
  • 13
  • 45
  • 80
0

If you're using custom Unity Assembly Definition files, then you cannot add references to that project in Visual Studio, as Unity overwrites the references when it compiles. Instead, you need to add the dll to your asset folder hierarchy.