【问题标题】:Android C# HtmlAgilityPackAndroid C# HtmlAgilityPack
【发布时间】:2012-12-10 21:23:18
【问题描述】:

如何在 Android 中使用 HtmlAgilityPack(Android 的 Mono - C#)?我已添加参考,但我不断收到此错误:

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

【问题讨论】:

  • 你解决过这个问题吗?我有完全相同的错误。我什至从 Xamarin 的 GitHub 下载了示例,并使用了他们在那里提供的编译好的 AgilityPack,但它仍然无法正常工作

标签: android html-agility-pack


【解决方案1】:

我已将 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

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

【讨论】:

    猜你喜欢
    • 2020-09-04
    • 2016-06-18
    • 1970-01-01
    • 2022-08-23
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-08
    相关资源
    最近更新 更多