2012-10-10 135 views
1

我正在从一个语言翻译程序中获取离线信息。我正在使用Unity游戏引擎,它使用Assembly作为它的IDE。以下是我的代码到目前为止。从汇编引用.dll c#

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

然而,编译时,我收到错误:

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? 

我开始做研究,听说HtmlAgilityPack是第三方软件,而且我不得不引用.dll文件。我下载了VisualStudio2010,以及NuGet。在Visual Studio里面,我点击了“管理NuGet包”并安装了HtmlAgilityPack。在Visual Studio内部,错误消失了,但是当我试图在Assembly中打开文件时,仍然收到错误,名称空间HtmlAgilityPack无法找到。我使用的是Unity游戏引擎,所以我必须从VisualStudio文件中取出文件并将其放置在不同的文件夹中。有没有我缺少的步骤,或者我需要在汇编中做些什么来引用HtmlAgilityPack dll?任何帮助将不胜感激。

+0

你有没有移动HtmlAgilityPack的*仓*到部署文件夹** **你组装? –

+0

难道http://stackoverflow.com/questions/12628449/html-agility-pack-implementation没有回答你的问题吗? –

+0

统一标签用于Microsoft Unity。请不要滥用它。 –

回答

2

引用HtmlAgilityPakc.dll像奥斯汀和沙基尔后说,我仍然无法得到错误的工作。我通过不仅引用了HtmlAgilityPack.dll,而且通过脚本将HtmlAgilityPack.dll放入该文件夹中修复了此错误。这摆脱了错误。感谢您所有的帮助!

1

尝试从添加引用标签添加HTMLAgility!

+0

您的问题是否已解决? –

+0

我点击了编辑引用并添加了HtmlAgilityPack.dll,但它仍然出现错误命名空间“HtmlAgilityPack”无法找到。你有什么想法来解决这个问题吗? –

+0

如果您使用与程序集关联的任何Webcontrol,则在.aspx页面上,在页面代码的开头添加以下行: <%@ Register Assembly =“HtmlAgilityPack”Namespace =“HtmlAgilityPack”TagPrefix = “htmlagl”%> 如果这项工作,它将是伟大的 –

1

在该项目下,去添加引用,并确保HTMLAgilityPack已添加。 由于您已有using HtmlAgilityPack;,因此应该修复。

在这个题目你other问题应该解决了这一点。