Solved

XmlSerializer Problem

Posted on 2014-03-22
10
276 Views
Last Modified: 2014-03-23
I have a data class with other classes embedded into it that I'm trying to Deserialize XML.
I keep getting an error on:

     XmlSerializer SerializerObj = new XmlSerializer(typeof(Contract));

"There was an error reflecting type Contract". The inner exception states that there is a property on the Contract class called State. The State class has a Base that has an Id property hat is a int64, but in the State class it is a string.

    public class State : BaseObject
    {
        private new String m_id;
        private string m_statename;
        //private string m_stateabbr;
        private IList m_statetradelist;

        [System.Xml.Serialization.XmlElement(DataType="string" ElementName="StateID")]
        public virtual new String Id
        {
            get { return m_id; }
            set { m_id = value; }
        }

        public virtual string StateName
        {
            get { return m_statename; }

            set
            {

                this.IsChanged |= (m_statename != value); m_statename = value;
            }
        }

Open in new window


What can I do to get past this?
Serialization-Error.JPG
0
Comment
Question by:csalerno
  • 6
  • 4
10 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39947899
the error says that you need to use either XmlElementAttribute or XmlAttributeAttribute to change the name of the Id property because the BaseObject also has an Id property but a different type.

Since you already have XmlElement, try

[XmlAttribute("StateID")]
0
 

Author Comment

by:csalerno
ID: 39947902
I've tried every combination I could think of with the same error.

   [System.Xml.Serialization.XmlAttribute(DataType="string", AttributeName="StateID")]

   [System.Xml.Serialization.XmlElementAttribute(DataType="string", ElementName="StateID")]

   [System.Xml.Serialization.XmlAttributeAttribute(DataType="string", AttributeName="StateID")]
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39947912
can you provide a full sample (BaseObject, State, Contract, serialization code) so I don't have to create it all?
0
 

Author Comment

by:csalerno
ID: 39947914
I will have to find out if I can release as it is proprietary code and would consist of about 20 other classes.
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39948511
I don't want all the classes. Just a sample replicating your issue
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:csalerno
ID: 39948698
Here is the BaseObject & Project Classes. Let me know if that helps.

namespace Luc.Business
{
    using log4net;
    using Lucas.ObjectAccess;
    using System;
    using System.Collections;

    [Serializable]
    public abstract class BaseObject : IObjectAccessListener
    {
        private static readonly ILog log = LogManager.GetLogger(typeof(BaseObject));
        protected long m_id;
        private bool m_isChanged;

        protected BaseObject()
        {
        }

        protected IList GetListener()
        {
            string str = base.GetType().ToString();
            return ObjectListenerFactory.GetObjectListener(str.Substring(str.LastIndexOf(".") + 1));
        }

        public virtual bool IsNew()
        {
            return (this.m_id == 0L);
        }

        public virtual void PostDelete()
        {
            IList listener = this.GetListener();
            if (listener != null)
            {
                for (int i = 0; i < listener.Count; i++)
                {
                    ((IObjectListener) listener[i]).PostDelete(this);
                }
            }
        }

        public virtual void PostSave()
        {
            IList listener = this.GetListener();
            if (listener != null)
            {
                for (int i = 0; i < listener.Count; i++)
                {
                    ((IObjectListener) listener[i]).PostSave(this);
                }
            }
        }

        public virtual void PreDelete()
        {
            IList listener = this.GetListener();
            if (listener != null)
            {
                for (int i = 0; i < listener.Count; i++)
                {
                    ((IObjectListener) listener[i]).PreDelete(this);
                }
            }
        }

        public virtual void PreSave(object currentUser)
        {
            log.Debug("Get the Listeners ");
            IList list = this.GetListener();
            if (list != null)
            {
                log.Debug("Call the listeners  " + list.Count);
                for (int i = 0; i < list.Count; i++)
                {
                    IObjectListener listener = (IObjectListener) list[i];
                    log.Debug("The iol is " + listener.GetType().Name);
                    listener.PreSave(this, currentUser);
                }
            }
        }

        public virtual void SetDefaults()
        {
            IList listener = this.GetListener();
            if (listener != null)
            {
                for (int i = 0; i < listener.Count; i++)
                {
                    ((IObjectListener) listener[i]).SetDefaults(this);
                }
            }
        }

        public virtual string FriendlyType
        {
            get
            {
                string name = base.GetType().Name;
                return name.Substring(name.LastIndexOf('.') + 1);
            }
        }

        
        public virtual long Id
        {
            get
            {
                return this.m_id;
            }
            set
            {
                this.m_id = value;
            }
        }

        public virtual bool IsChanged
        {
            get
            {
                return this.m_isChanged;
            }
            set
            {
                this.m_isChanged = value;
            }
        }
    }
}

using System.Linq;
using DTPLibrary.ExtensionMethods;
/*
insert license info here
*/
using System;
using System.Collections;

using Lucas.Business;
using log4net;


namespace DTP.Data
{
    /// <summary>
    ///	Generated by MyGeneration using the NHibernate Object Mapping template
    /// </summary>
    [Serializable]
    public class Project : BaseObject
    {
        public enum PMLetterRedirection
        {
            Off = 0,
            CCOnLetters = 1,
            PrimaryOnLetters = 2
        }

        ILog log = LogManager.GetLogger("Data.Project");

        #region Private Members
        
        private CertGenLetterTempl m_CertTempl;
        private BondLetterTempl m_BondTempl;
        private LetterTemplWrap m_WrapTempl;
        private IList m_AddInsReqList;
        private string m_projectnumber;
        private IList m_InsuredProjectBondList;
        private IList m_CertWrapList;
        private IList m_ContractList;
        private IList m_ProjectCertReqList;
        private IList m_ProjectWrapReqList;
        private IList m_WebUserList;
        private IList m_insuredList;
        private IList m_wrapreqList;
        private IList m_certreqList;
        private IList m_certList;
        private IList m_CertLettTemplList;
        private IList m_BondLettTemplList;
        private IList m_stateList;
        private string m_name;
        private ProjectType m_projecttype;
        private WrapOwner m_owner;
        private Broker m_broker;
        private GeneralContr m_generalcontr;
        private short m_numberofphases;
        private DateTime? m_startdate;
        private DateTime? m_enddate;
        private string m_signature;
        private string m_sirstatement;
        private string m_address1;
        private string m_address2;
        private string m_city;
        private State m_state;
        private string m_strstate;
        private string m_zip;
        private string m_phone;
        private string m_mobile;
        private string m_fax;
        private string m_contact;
        private string m_contactemail;
        private bool m_CCIP;
        private bool m_OCIP;
        private bool m_EnrollmentOnly;
        private bool m_ChangeAddInsReq;
        //private IList m_ClientList;
        private short m_ClientID;
        private string m_pmcontactname  ;
        private string m_pmaddr1  ;
        private string m_pmaddr2  ;
        private string m_pmcity  ;
        private string m_pmstate ;
        private string m_pmzip  ;
        private string m_pmphone;
        private string m_pmfax ;
        private string m_pmmobile  ;
        private string m_pmemail  ;
        private int m_pmletterredirect;
        #endregion

        #region Default ( Empty ) Class Constuctor
        /// <summary>
        /// default constructor
        /// </summary>
        public Project()
        {

        }
        #endregion // End of Default ( Empty ) Class Constuctor

        #region Public Properties

        /// <summary>
        /// 
        /// </summary>
        /// 
       [System.Xml.Serialization.XmlAttributeAttribute()]
        public override long Id
        {
            get { return m_id; }
            set { m_id = value; }
        }

        public virtual IList SortedInsuredList
        {
			get
			{
				return InsuredList;            
			}
            /*get
            {
                if (InsuredList != null)
                {
                    SortedList sortedInsured = new SortedList();
                    for (int i = 0; i < InsuredList.Count; i++)
                    {

                        Data.Insured insured = (Data.Insured)InsuredList[i];
                        log.Debug("The insured is " + insured.VendorName + " id = " + insured.Id);
                        sortedInsured.Add(insured.VendorName, insured);
                    }
                    return sortedInsured.GetValueList();
                }
                else
                {
                    return null;
                }
            }*/
        }

		public virtual void ClearInsuredList()
		{
			m_insuredList = null;
		}
        public virtual IList InsuredList
        {
			get
			{
				m_insuredList = new DTP.DB.SelectInsureds(this).Records.OrderBy(LoopInsured => LoopInsured.VendorName).ToList();
				return m_insuredList;
			}
            //get { return m_insuredList; }
            set { m_insuredList = value; }
        }

        public virtual IList CertList
        {
            get { return m_certList; }
            set { m_certList = value; }
        }
        public virtual IList StateList
        {
            get { return m_stateList; }
            set { m_stateList = value; }
        }
        public virtual CertGenLetterTempl CertTempl
        {
            get { return m_CertTempl; }
            set { m_CertTempl = value; }
        }

        public virtual BondLetterTempl BondTempl
        {
            get { return m_BondTempl; }
            set { m_BondTempl = value; }
        }

        public virtual LetterTemplWrap WrapTempl
        {
            get { return m_WrapTempl; }
            set { m_WrapTempl = value; }
        }
        public virtual IList InsuredProjectBondList
        {
            get
            {
				if (m_InsuredProjectBondList == null)
				{
					m_InsuredProjectBondList = new DTP.DB.SelectInsuredProjectBond(new Insured
					{
						Id = -1
					}, this).Records;
				}
                return m_InsuredProjectBondList;
            }
            set
            {
                m_InsuredProjectBondList = value;
            }
        }
        public virtual IList CertWrapList
        {
            get
            {
                return m_CertWrapList;
            }
            set
            {
                m_CertWrapList = value;
            }
        }
        public virtual IList AddInsReqList
        {
			get
			{
				if (m_AddInsReqList == null)
				{
					m_AddInsReqList = new DTP.DB.SelectAdditionalInsuredsRequired(this, new Cert
					{
						Id = -1
					}).Records.OrderBy(LoopAdditionalInsuredRequired => LoopAdditionalInsuredRequired.AddIns.AddInsName).ToList();
				}
				return m_AddInsReqList;
			}
            set
            {
				m_AddInsReqList = value.ToList<AddInsReq>().OrderBy(LoopAdditionalInsuredRequired => LoopAdditionalInsuredRequired.AddIns.AddInsName).ToList();
                m_ChangeAddInsReq = true;
            }
        }

        public virtual IList SortedContractList
        {
            get
            {
				return ContractList.ToList<Contract>().OrderBy(LoopContract => LoopContract.Insured.VendorName).ToList();
				/*
                log.Debug("Getting a sorted list of contracts");
                if (ContractList != null)
                {
                    SortedList sortedContract = new SortedList();
                    for (int i = 0; i < ContractList.Count; i++)
                    {

                        Data.Contract contract = (Data.Contract)ContractList[i];

                        if (!sortedContract.Contains(contract.Insured.VendorName))
                        {
                            sortedContract.Add(contract.Insured.VendorName, contract);
                        }
                    }
                    return sortedContract.GetValueList();
                }
                else
                {
                    log.Debug("The Contract List is null");
                    return null;
                }
				*/
            }
        }


        //public virtual IList ClientList
        //{
        //    get
        //    {
        //        m_ClientList = new DTP.DB.SelectClients().Records.ToList();
        //        return m_ClientList;
        //    }

        //    set { m_ClientList = value; }
        //}

        public virtual IList ContractList
        {
            get
            {
				if (m_ContractList == null)
				{
					m_ContractList = new DTP.DB.SelectContracts(Id, true, true).Records;
				}
                return m_ContractList;
            }
            set
            {
                m_ContractList = value;
            }
        }

        public virtual IList ProjectCertReqList
        {
            get
            {
                return m_ProjectCertReqList;
            }
            set
            {
                m_ProjectCertReqList = value;
            }
        }

        public virtual IList ProjectWrapReqList
        {
            get
            {
                return m_ProjectWrapReqList;
            }
            set
            {
                m_ProjectWrapReqList = value;
            }
        }

        public virtual IList WrapReqList
        {
            get
            {
                this.IsChanged = true;
                return m_wrapreqList;
            }
            set
            {
                m_wrapreqList = value;
            }
        }
        public virtual IList CertReqList
        {
            get
            {
                return m_certreqList;
            }
            set
            {
                this.IsChanged = true;
                m_certreqList = value;
            }
        }
        public virtual IList WebUserList
        {
            get
            {
                return m_WebUserList;
            }
            set
            {
                m_WebUserList = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Project_Number
        {
            get { return m_projectnumber; }

            set
            {
                if (value == null)
                    throw new ArgumentOutOfRangeException("Null value not allowed for Project", value, "null");

                if (value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Project", value, value.ToString());

                this.IsChanged |= (m_projectnumber != value); m_projectnumber = value;
            }
        }

        ///<summary>
        ///
        ///</summary>
        ///
        public virtual string Signature
        {
            get { return m_signature; }

            set
            {
                this.IsChanged |= (m_signature != value); m_signature = value;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public virtual string Name
        {
            get { return m_name; }

            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for ProjName", value, value.ToString());

                this.IsChanged |= (m_name != value); m_name = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
		public virtual void ClearProjectType()
		{
			m_projecttype = null;
			;
		}
        public virtual ProjectType ProjectType
        {
			get
			{
				if (m_projecttype == null)
				{
					m_projecttype = new DTP.DB.SelectProjectType(this).Record ?? new ProjectType
					{
						Name = "", 
						Id = 0
					};
				}
				return m_projecttype;
			}

            set
            {
                this.IsChanged |= (m_projecttype != value); m_projecttype = value;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        public virtual WrapOwner Owner
        {
            get { return m_owner; }
            set
            {
                this.IsChanged |= (m_owner != value);
                m_owner = value;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        public virtual Broker Broker
        {
            get { return m_broker; }
            set
            {
                this.IsChanged |= (m_broker != value);
                m_broker = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual GeneralContr GeneralContr
        {
            get { return m_generalcontr; }
            set
            {
                this.IsChanged |= (m_generalcontr != value);
                m_generalcontr = value;
            }

        }


        /// <summary>
        /// 
        /// </summary>
        public virtual short NumberOfPhases
        {
            get { return m_numberofphases; }
            set
            {
                this.IsChanged |= (m_numberofphases != value);
                m_numberofphases = value;
            }

        }


        /// <summary>
        /// 
        /// </summary>
        public virtual string SirStatement
        {
            get { return m_sirstatement; }

            set
            {
                if (value != null && value.Length > 1000)
                    throw new ArgumentOutOfRangeException("Invalid value for SirStatement", value, value.ToString());

                this.IsChanged |= (m_sirstatement != value); m_sirstatement = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual DateTime? StartDate
        {
            get { return m_startdate; }
            set
            {
                this.IsChanged |= (m_startdate != value);
                m_startdate = value;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        public virtual DateTime? EndDate
        {
            get { return m_enddate; }
            set
            {
                this.IsChanged |= (m_enddate != value);
                m_enddate = value;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Address1
        {
            get { return m_address1; }

            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Address1", value, value.ToString());

                this.IsChanged |= (m_address1 != value); m_address1 = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Address2
        {
            get { return m_address2; }

            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Address2", value, value.ToString());

                this.IsChanged |= (m_address2 != value); m_address2 = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string City
        {
            get { return m_city; }

            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for City", value, value.ToString());

                this.IsChanged |= (m_city != value); m_city = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual State State
        {
            get { return m_state; }
            set
            {
//                m_state = new DTP.DB.SelectState(Id, true, true).Records;
                this.IsChanged |= (m_state != value);
                m_state = value;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string strState
        {
            get { return m_strstate; }
            set
            {
                //                m_state = new DTP.DB.SelectState(Id, true, true).Records;
                this.IsChanged |= (m_strstate != value);
                m_strstate = value;
            }

        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Zip
        {
            get { return m_zip; }

            set
            {
                if (value != null && value.Length > 10)
                    throw new ArgumentOutOfRangeException("Invalid value for Zip", value, value.ToString());

                this.IsChanged |= (m_zip != value); m_zip = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Phone
        {
            get { return m_phone; }

            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Phone", value, value.ToString());

                this.IsChanged |= (m_phone != value); m_phone = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Fax
        {
            get { return m_fax; }

            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Fax", value, value.ToString());

                this.IsChanged |= (m_fax != value); m_fax = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Mobile
        {
            get { return m_mobile; }

            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Email", value, value.ToString());

                this.IsChanged |= (m_mobile != value); m_mobile = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string Contact
        {
            get { return m_contact; }

            set
            {
//                if (value != null && value.Length > 50)
//                    throw new ArgumentOutOfRangeException("Invalid value for ContactName", value, value.ToString());

                this.IsChanged |= (m_contact != value); m_contact = value;
            }
        }

        public virtual string ContactEmail
        {
            get { return m_contactemail; }

            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for ContactName", value, value.ToString());

                this.IsChanged |= (m_contactemail != value); m_contactemail = value;
            }
        }

        public virtual bool CCIP
        {
            get { return m_CCIP; }

            set
            {

                this.IsChanged |= (m_CCIP != value);
                Console.WriteLine("The this.IsChanged is " + this.IsChanged);
                m_CCIP = value;
            }
        }

        public virtual bool OCIP
        {
            get { return m_OCIP; }

            set
            {

                this.IsChanged |= (m_OCIP != value);
                Console.WriteLine("The this.IsChanged is " + this.IsChanged);
                m_OCIP = value;
            }
        }

        public virtual bool EnrollmentOnly
        {
            get { return m_EnrollmentOnly; }

            set
            {

                this.IsChanged |= (m_EnrollmentOnly != value); m_EnrollmentOnly = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual short ClientID
        {
            get { return m_ClientID; }
            set
            {
                this.IsChanged |= (m_ClientID != value);
                m_ClientID = value;
            }

        }


        public virtual bool ChangeAddInsReq
        {
            get { return m_ChangeAddInsReq; }
            set { m_ChangeAddInsReq = false; }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string PMContactName
        {
            get { return m_pmcontactname; }

            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for Contact Name", value, value.ToString());

                this.IsChanged |= (m_pmcontactname != value); m_pmcontactname = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string PMAddr1
        {
            get { return m_pmaddr1; }

            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for Contact Address", value, value.ToString());

                this.IsChanged |= (m_pmaddr1 != value); m_pmaddr1 = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string PMAddr2
        {
            get { return m_pmaddr2; }

            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for Contact Address", value, value.ToString());

                this.IsChanged |= (m_pmaddr2 != value); m_pmaddr2 = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string PMCity
        {
            get { return m_pmcity; }

            set
            {
                if (value != null && value.Length > 50)
                    throw new ArgumentOutOfRangeException("Invalid value for Contact City", value, value.ToString());

                this.IsChanged |= (m_pmcity != value); m_pmcity = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string PMState
        {
            get { return m_pmstate; }

            set
            {
                if (value != null && value.Length > 2)
                    throw new ArgumentOutOfRangeException("Invalid value for Contact State", value, value.ToString());

                this.IsChanged |= (m_pmstate != value); m_pmstate = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string PMZip
        {
            get { return m_pmzip; }

            set
            {
                if (value != null && value.Length > 10)
                    throw new ArgumentOutOfRangeException("Invalid value for Contact Zip", value, value.ToString());

                this.IsChanged |= (m_pmzip != value); m_pmzip = value;
            }
        }


        /// <summary>
        /// 
        /// </summary>
        public virtual string PMPhone
        {
            get { return m_pmphone; }

            set
            {
                if (value != null && value.Length > 15)
                    throw new ArgumentOutOfRangeException("Invalid value for Contact Phone", value, value.ToString());

                this.IsChanged |= (m_pmphone != value); m_pmphone = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string PMFax
        {
            get { return m_pmfax; }

            set
            {
                if (value != null && value.Length > 15)
                    throw new ArgumentOutOfRangeException("Invalid value for Contact Fax", value, value.ToString());

                this.IsChanged |= (m_pmfax != value); m_pmfax = value;
            }
        }

        
        
        /// <summary>
        /// 
        /// </summary>
        public virtual string PMMobile
        {
            get { return m_pmmobile; }

            set
            {
                if (value != null && value.Length > 15)
                    throw new ArgumentOutOfRangeException("Invalid value for Mobile Phone", value, value.ToString());

                this.IsChanged |= (m_pmmobile != value); m_pmmobile = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual string PMEmail
        {
            get { return m_pmemail; }

            set
            {
                if (value != null && value.Length > 100)
                    throw new ArgumentOutOfRangeException("Invalid value for Email", value, value.ToString());

                this.IsChanged |= (m_pmemail != value); m_pmemail = value;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        public virtual int PMLetterRedirect
        {
            get { return m_pmletterredirect; }

            set
            {

                this.IsChanged |= (m_pmletterredirect != value); m_pmletterredirect = value;
            }
        }

        public override String ToString()
        {
            return m_name;
        }

        #endregion

        #region Equals And HashCode Overrides
        /// <summary>
        /// local implementation of Equals based on unique value members
        /// </summary>
        public override bool Equals(object obj)
        {
            if (this == obj) return true;
            if ((obj == null) || (obj.GetType() != this.GetType())) return false;
            Project castObj = (Project)obj;
            return (castObj != null) &&
                (this.m_id == castObj.m_id);
        }

        /// <summary>
        /// local implementation of GetHashCode based on unique value members
        /// </summary>
        public override int GetHashCode()
        {

            int hash = 57;
            hash = 27 * hash * m_id.GetHashCode();
            return hash;
        }
        #endregion
    }
}

Open in new window

0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39948731
1098 lines! I wasn't expecting more than 50! I'll be back in about 2 hours
0
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 39948832
it is totally useless!

can you create a sample of 50 lines max replication your problems?
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 39948888
It seems that the error is misleading! An old post (https://groups.google.com/forum/#!topic/microsoft.public.dotnet.xml/QxItJT-SwiI) says that it is not supported.

Here is something working (by adding the XmlIgnore attribute in the base class):

using System;
using System.IO;
using System.Windows.Forms;
using System.Xml.Serialization;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var obj1 = new State();
            obj1.Id = "1";
            var serializerObj = new XmlSerializer(typeof(State));
            var stm = new MemoryStream();
            serializerObj.Serialize(stm, obj1);
            stm.Position = 0;

            textBox1.Text = new StreamReader(stm).ReadToEnd();
        }
    }

    [Serializable]
    public class State : BaseObject
    {

        [XmlElement(ElementName = "StateID")]
        public new string Id { get; set; }

    }

    [Serializable]
    public abstract class BaseObject //: IObjectAccessListener
    {

        [XmlIgnore]
        public virtual long Id { get; set; }
    }

}
0
 

Author Comment

by:csalerno
ID: 39948912
The XmlIgnore tag worked. I'm not able to call the XmlSerializer method without error.

thank you
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Visual xHarbour 1 76
mergeTwo  challenge 13 72
python sqlite question 11 43
parse convert xml feed to text (python) 2 31
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now