I am receiving the following error while attempting to create an XML file based on an XML schema document:
Message = "Cannot serialize member 'CountyIreland' of type System.Nullable`1[XmlMessageConnector.Data.AddressTypeCountyIreland]. XmlAttribute/XmlText cannot be used to encode complex types."
[System.Xml.Serialization.XmlAttributeAttribute()] public AddressTypeCountyIreland? CountyIreland { get { return this._countyIreland; } set { this._countyIreland = value; _shouldSerializeCountyIreland = true; } } The AddressType class is as follows:
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.6.81.0"), System.SerializableAttribute(), System.Diagnostics.DebuggerStepThroughAttribute(), System.ComponentModel.DesignerCategoryAttribute("code"), System.Xml.Serialization.XmlRootAttribute("MeterPointAddress", Namespace = "", IsNullable = false)] public partial class AddressType { private bool _shouldSerializeCountry; private bool _shouldSerializeCountyIreland; private string _unitNo; private string _addrLine1; private string _addrLine2; private string _houseNo; private string _street; private string _addrLine4; private string _addrLine5; private string _postCode; private string _city; private AddressTypeCountyIreland? _countyIreland; private bool countyIrelandFieldSpecified; private AddressTypeCountry? _country; private bool countryFieldSpecified; private static XmlSerializer sSerializer; private bool _unitNoSpecified; private bool _addrLine1Specified; private bool _addrLine2Specified; private bool _houseNoSpecified; private bool _streetSpecified; private bool _addrLine4Specified; private bool _addrLine5Specified; private bool _postCodeSpecified; private bool _citySpecified; [System.Xml.Serialization.XmlAttributeAttribute()] public string UnitNo { get { return this._unitNo; } set { this._unitNo = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public string AddrLine1 { get { return this._addrLine1; } set { this._addrLine1 = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public string AddrLine2 { get { return this._addrLine2; } set { this._addrLine2 = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public string HouseNo { get { return this._houseNo; } set { this._houseNo = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public string Street { get { return this._street; } set { this._street = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public string AddrLine4 { get { return this._addrLine4; } set { this._addrLine4 = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public string AddrLine5 { get { return this._addrLine5; } set { this._addrLine5 = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public string PostCode { get { return this._postCode; } set { this._postCode = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public string City { get { return this._city; } set { this._city = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public AddressTypeCountyIreland? CountyIreland { get { return this._countyIreland; } set { this._countyIreland = value; _shouldSerializeCountyIreland = true; } } [System.Xml.Serialization.XmlIgnoreAttribute()] public bool CountyIrelandSpecified { get { return this.countyIrelandFieldSpecified; } set { this.countyIrelandFieldSpecified = value; } } [System.Xml.Serialization.XmlAttributeAttribute()] public AddressTypeCountry? Country { get { return this._country; } set { this._country = value; _shouldSerializeCountry = true; } } [System.Xml.Serialization.XmlIgnoreAttribute()] public bool CountrySpecified { get { return this.countryFieldSpecified; } set { this.countryFieldSpecified = value; } } private static XmlSerializer Serializer { get { if ((sSerializer == null)) { sSerializer = new XmlSerializerFactory().CreateSerializer(typeof(AddressType)); } return sSerializer; } } [XmlIgnore()] public bool UnitNoSpecified { get { return this._unitNoSpecified; } set { this._unitNoSpecified = value; } } [XmlIgnore()] public bool AddrLine1Specified { get { return this._addrLine1Specified; } set { this._addrLine1Specified = value; } } [XmlIgnore()] public bool AddrLine2Specified { get { return this._addrLine2Specified; } set { this._addrLine2Specified = value; } } [XmlIgnore()] public bool HouseNoSpecified { get { return this._houseNoSpecified; } set { this._houseNoSpecified = value; } } [XmlIgnore()] public bool StreetSpecified { get { return this._streetSpecified; } set { this._streetSpecified = value; } } [XmlIgnore()] public bool AddrLine4Specified { get { return this._addrLine4Specified; } set { this._addrLine4Specified = value; } } [XmlIgnore()] public bool AddrLine5Specified { get { return this._addrLine5Specified; } set { this._addrLine5Specified = value; } } [XmlIgnore()] public bool PostCodeSpecified { get { return this._postCodeSpecified; } set { this._postCodeSpecified = value; } } [XmlIgnore()] public bool CitySpecified { get { return this._citySpecified; } set { this._citySpecified = value; } } ///<summary> ///Test whether CountyIreland should be serialized ///</summary> public virtual bool ShouldSerializeCountyIreland() { if (_shouldSerializeCountyIreland) { return true; } return (_countyIreland.HasValue); } ///<summary> ///Test whether Country should be serialized ///</summary> public virtual bool ShouldSerializeCountry() { if (_shouldSerializeCountry) { return true; } return (_country.HasValue); } ///<summary> ///Test whether UnitNo should be serialized ///</summary> public virtual bool ShouldSerializeUnitNo() { return !string.IsNullOrEmpty(UnitNo); } ///<summary> ///Test whether AddrLine1 should be serialized ///</summary> public virtual bool ShouldSerializeAddrLine1() { return !string.IsNullOrEmpty(AddrLine1); } ///<summary> ///Test whether AddrLine2 should be serialized ///</summary> public virtual bool ShouldSerializeAddrLine2() { return !string.IsNullOrEmpty(AddrLine2); } ///<summary> ///Test whether HouseNo should be serialized ///</summary> public virtual bool ShouldSerializeHouseNo() { return !string.IsNullOrEmpty(HouseNo); } ///<summary> ///Test whether Street should be serialized ///</summary> public virtual bool ShouldSerializeStreet() { return !string.IsNullOrEmpty(Street); } ///<summary> ///Test whether AddrLine4 should be serialized ///</summary> public virtual bool ShouldSerializeAddrLine4() { return !string.IsNullOrEmpty(AddrLine4); } ///<summary> ///Test whether AddrLine5 should be serialized ///</summary> public virtual bool ShouldSerializeAddrLine5() { return !string.IsNullOrEmpty(AddrLine5); } ///<summary> ///Test whether PostCode should be serialized ///</summary> public virtual bool ShouldSerializePostCode() { return !string.IsNullOrEmpty(PostCode); } ///<summary> ///Test whether City should be serialized ///</summary> public virtual bool ShouldSerializeCity() { return !string.IsNullOrEmpty(City); } #region "Serialize/Deserialize" ///<summary> ///Serializes current AddressType object into an XML string ///</summary> ///<returns>string XML value</returns> public virtual string Serialize() { System.IO.StreamReader streamReader = null; System.IO.MemoryStream memoryStream = null; try { memoryStream = new System.IO.MemoryStream(); System.Xml.XmlWriterSettings xmlWriterSettings = new System.Xml.XmlWriterSettings(); xmlWriterSettings.Indent = false; System.Xml.XmlWriter xmlWriter = XmlWriter.Create(memoryStream, xmlWriterSettings); Serializer.Serialize(xmlWriter, this); memoryStream.Seek(0, System.IO.SeekOrigin.Begin); streamReader = new System.IO.StreamReader(memoryStream); return streamReader.ReadToEnd(); } finally { if ((((streamReader) != null))) { streamReader.Dispose(); } if ((((memoryStream) != null))) { memoryStream.Dispose(); } } } ///<summary> ///Deserializes workflow markup into an AddressType object ///</summary> ///<param name="input">string workflow markup to deserialize</param> ///<param name="obj">Output AddressType object</param> ///<param name="exception">output Exception value if deserialize failed</param> ///<returns>true if this Serializer can deserialize the object; otherwise, false</returns> public static bool Deserialize(string input, ref AddressType obj, ref System.Exception exception) { exception = null; obj = (AddressType)null; try { obj = Deserialize(input); return true; } catch (System.Exception ex) { exception = ex; return false; } } public static bool Deserialize(string input, ref AddressType obj) { System.Exception exception = null; return Deserialize(input, ref obj, ref exception); } public static AddressType Deserialize(string input) { System.IO.StringReader stringReader = null; try { stringReader = new System.IO.StringReader(input); return (AddressType)Serializer.Deserialize(System.Xml.XmlReader.Create(stringReader)); } finally { if ((((stringReader) != null))) { stringReader.Dispose(); } } } public static AddressType Deserialize(System.IO.Stream s) { return (AddressType)Serializer.Deserialize(s); }
No comments:
Post a Comment