Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue referencing System.Xml for external library using IXmlSerializable
    text
    copied!<p>I've updated to a recent version of Xamarin Studio and a class I use shared with Visual Studio is no longer working between the 2 platforms. I've run into some compilation/runtime errors involving XML serialization. I have a library with the following class compiled in Xamarin studio:</p> <pre><code>[XmlRoot("dictionary")] [Serializable] public class SerializableDictionary&lt;TKey, TValue&gt; : Dictionary&lt;TKey, TValue&gt;, IXmlSerializable { #region IXmlSerializable Members public SerializableDictionary() { } public System.Xml.Schema.XmlSchema GetSchema() { return null; } public void ReadXml(System.Xml.XmlReader reader) { XmlSerializer keySerializer = new XmlSerializer(typeof(TKey)); XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue)); bool wasEmpty = reader.IsEmptyElement; reader.Read(); if (wasEmpty) return; while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { reader.ReadStartElement("item"); reader.ReadStartElement("key"); TKey key = (TKey)keySerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement("value"); TValue value = (TValue)valueSerializer.Deserialize(reader); reader.ReadEndElement(); this.Add(key, value); reader.ReadEndElement(); reader.MoveToContent(); } reader.ReadEndElement(); } public void WriteXml(System.Xml.XmlWriter writer) { XmlSerializer keySerializer = new XmlSerializer(typeof(TKey)); XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue)); foreach (TKey key in this.Keys) { writer.WriteStartElement("item"); writer.WriteStartElement("key"); keySerializer.Serialize(writer, key); writer.WriteEndElement(); writer.WriteStartElement("value"); TValue value = this[key]; valueSerializer.Serialize(writer, value); writer.WriteEndElement(); writer.WriteEndElement(); } } #endregion } </code></pre> <p>I've compiled this DLL and am referencing it in a Windows project in Visual Studio like this:</p> <pre><code>SerializableDictionary&lt;string, string&gt; asdf = new SerializableDictionary&lt;string, string&gt;(); </code></pre> <p>This gives the compilation error: "The type 'System.Xml.Serialization.IXmlSerializable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'"</p> <p>Of course, I do actually have a reference to System.Xml. In fact if I copy the class from Xamarin and paste it into the project on the Visual Studio side, the class works fine. There's a few variations of this error depending how I structure things, but this one seems to be the root cause.</p> <p>Anyone have ideas why this library isn't working cross platform any more? Did something change with IXmlSerializable in the latest versions of Xamarin?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload