Reputation: 309
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.
Upvotes: 1
Views: 4376
Reputation: 3
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.
Upvotes: 0
Reputation: 309
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!
Upvotes: 2
Reputation: 4633
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.
Upvotes: 1