适用于Android和iOS的xamarin中的XmlTextWriter

时间:2016-04-06 10:45:33

标签: c# xamarin xmltextwriter system.xml

我有一些专有代码,我正在尝试使用Xamarin studio for mac在xamarin项目中编译。其中一个类使用System.Xml.XmlTextWriter。

我收到以下错误:

Error CS0012: The type `System.Xml.XmlTextWriter' is defined in an assembly
that is not referenced. Consider adding a reference to assembly `System.Xml,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 

首先,我在项目中添加了对System.Xml的引用。这是一个共享库(不是可移植的),因此引用是在droid项目中,而不是库项目本身。

我知道Xamarin中的System.Xml的某些部分存在问题(请参阅 [1][2]),但它们似乎围绕着XmlDocument。此外,the xamarin documentation specifically has XmlTextWriter in it(假设此文档适用于xamarin库,而不是它们所基于的windows文档)。

此文档以及上述错误提及我需要版本2.0.0.0 where as the Reference available to me is 2.0.5.0。我不确定这是否重要。

有人有什么想法吗?

u_u

2 个答案:

答案 0 :(得分:1)

您是否尝试在项目中添加绑定重定向?

添加名为app.config的文件,内容为:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Xml" publicKeyToken="b77a5c561934e089" culture="neutral" />
                <bindingRedirect oldVersion="0.0.0.0-2.0.5.0" newVersion="2.0.5.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

答案 1 :(得分:1)

似乎该库是针对.NET 2.0 / 3.5编译的,并期望在该环境中构建/运行。 2.0.5.0是Xamarin的移动目标,我不完全确定bindingRedirect是以这种方式工作的。你能验证专有的lib是否针对移动设备?或者,检查其“platformness”,如果一切正常,您可以编辑程序集以重新定位它。