简体   繁体   中英

XmlTextWriter in xamarin for android and iOS

I have some proprietary code that I am trying to compile in a xamarin project using Xamarin studio for mac. One of the classes uses System.Xml.XmlTextWriter.

I am getting the following error:

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' 

Firstly I have added the reference to System.Xml in my project. This is a shared library (not a portable one) so the reference is in the droid project, and not the library project itself.

I know there are issues with certain parts of System.Xml in Xamarin (see [1] , [2] ) but they seem to revolve around XmlDocument. Furthermore, the xamarin documentation specifically has XmlTextWriter in it (assume this documentation is for the xamarin libraries, and not the windows ones they are based on).

This documentation, as well as the error above, mentions that I need version 2.0.0.0 , where as the Reference available to me is 2.0.5.0 . I am unsure if this matters.

Anyone have any ideas?

u_u

Have you tried adding a binding redirect in your project?

Add a file called app.config with the contents:

<?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>

It seems that the library is compiled against .NET 2.0/3.5, and expecting to build/run in that environment. The 2.0.5.0 is Xamarin's mobile target, and I'm not entirely sure that bindingRedirect is meant to work in that way. Can you verify that the proprietary lib is targeting mobile? Alternatively, check its " platformness ," and if everything looks good, you could possibly edit the assembly to retarget it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM