2

如何将 HtmlAgilityPack 与 Android 一起使用(Mono for Android - C#)?我已添加参考,但我不断收到此错误:

错误 CS0012:在未引用的程序集中定义了类型“System.Xml.XPath.IXPathNavigable”。您必须添加对程序集 'System.Xml, Version=2.0.0.0 的引用

4

1 回答 1

0

我已将 HtmlAglilityPack 合并到我在所有 MonoDroid 项目中使用的基本库程序集中,并取得了巨大成功。我什至没有尝试以预编译的形式使用它们,只是将它的源代码添加到我的项目中。

然后我无耻地编辑了 HtmlWeb.cs 以丢弃 Windows 的东西:

第 893 到 903 行(可能有所改变,看看附近):

        if (!helper.GetIsDnsAvailable())
        {
        #if Android
            contentType = def;
        #else
            //do something.... not at full trust
            try
            {
                RegistryKey reg = Registry.ClassesRoot;
                reg = reg.OpenSubKey(extension, false);
                if (reg != null) contentType = (string)reg.GetValue("", def);
            }
            catch (Exception)
            {
                contentType = def;
            }
        #endif
        }

第 934 到 946 行(可能有些变化,看看附近):

        if (helper.GetIsRegistryAvailable())
        {
        #if Android
            ext = def;
        #else
            try
            {
                RegistryKey reg = Registry.ClassesRoot;
                reg = reg.OpenSubKey(@"MIME\Database\Content Type\" + contentType, false);
                if (reg != null) ext = (string)reg.GetValue("Extension", def);
            }
            catch (Exception)
            {
                ext = def;
            }
        #endif
        }

然后我添加Android到我的项目的条件编译符号中。

我的参考资料是:

Microsoft.CSharp
Mono.Android
System
System.Core
System.Data
System.Xml
System.Xml.Linq

请添加评论,告诉您是否可以现在编译它,或者您是否需要更多信息。

于 2015-04-22T08:22:44.160 回答