XmlTextWriter in xamarin for android and iOS

311 views Asked by At

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

2

There are 2 answers

4
Cheesebaron On

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>
1
joe On

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.