using System; using System.IO; using System.Xml.Serialization; class Program { static public T DeserializeFromString(string xml) where T : class { if (String.IsNullOrEmpty(xml)) { return null; } StringReader reader = null; T deserializedObject = null; try { reader = new StringReader(xml); XmlSerializer serializer = new XmlSerializer(typeof(T)); deserializedObject = serializer.Deserialize(reader) as T; } finally { if (null != reader) { reader.Close(); } } return deserializedObject; } static void Main(string[] args) { string myXML = @""; // The following line fails on Mono 2.8 2.10 2.10.8.1 2.10.9 TASK data = DeserializeFromString(myXML); if(data == null) { throw new Exception("A#01"); } if(data.ItemElementName != ItemChoiceType.OptionA) { throw new Exception("A#02"); } } } // Below is the code generated from the following XSD: /* */ //------------------------------------------------------------------------------ // // This code was generated by a tool. // Runtime Version:4.0.30319.239 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // //------------------------------------------------------------------------------ // // This source code was auto-generated by xsd, Version=4.0.30319.1. // /// [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute("code")] [System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)] [System.Xml.Serialization.XmlRootAttribute(Namespace="", IsNullable=false)] public partial class TASK { private object itemField; private ItemChoiceType itemElementNameField; /// [System.Xml.Serialization.XmlElementAttribute("OptionA", typeof(object), Order=0)] [System.Xml.Serialization.XmlElementAttribute("OptionB", typeof(object), Order=0)] [System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemElementName")] public object Item { get { return this.itemField; } set { this.itemField = value; } } /// [System.Xml.Serialization.XmlElementAttribute(Order=1)] [System.Xml.Serialization.XmlIgnoreAttribute()] public ItemChoiceType ItemElementName { get { return this.itemElementNameField; } set { this.itemElementNameField = value; } } } /// [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.1")] [System.SerializableAttribute()] [System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)] public enum ItemChoiceType { /// OptionA, /// OptionB, }