0

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

Community
  • 1
  • 1
Jason Ridge
  • 1,868
  • 15
  • 27

2 Answers2

1

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>
Cheesebaron
  • 24,131
  • 15
  • 66
  • 118
  • Thats cool! I added the file, but it doesn't seem to work. I checked the build properties and its build action is none, what build action should I use? Any other reason it wouldnt work? – Jason Ridge Apr 06 '16 at 11:34
  • Ah I see that it might be an issue with using this app.config in xamarin. Theres an assemblyinfo.cs file I can use, so Im taking a look at that now – Jason Ridge Apr 06 '16 at 11:36
  • that was nogud. But I found this link: https://forums.xamarin.com/discussion/11837/cross-platform-assembly-nightmare-can-somebody-please-help which talks a similar issue. with another dll. Looking into it... Some people say they always add redirects, others say it should be handled automatically. I wonder if this is a red herring – Jason Ridge Apr 06 '16 at 11:57
  • I've had mixed results with bindingRedirect. I've heard that Xamarin handles it automatically (with or without them), while Microsoft requires it. Both seem to add them by themselves, and I generally leave them alone unless something breaks. – joe Apr 06 '16 at 13:32
1

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.

joe
  • 1,125
  • 9
  • 18
  • Thanks for the link on platformness, I'll give that a try. Im also going to make a dummy project with the code and see if it will compile. – Jason Ridge Apr 06 '16 at 13:59