none
Getting Serialized error when I split the client and server on 2 different computers. RRS feed

  • Question

  •  

    Hello,

    I am receiving the error 'Type UserService.User cannot be serialized. Consider marking it with the DataContractAttribute attribute, and making all of  its members you want serialized with the DataMemberAttribute attribute.' Here is my DataContract:

     

     

    [DataContract]
      [Flags]
      public enum UserSubscriptions
      {
        /// <summary>
        /// No item subscriptions
        /// </summary>
        [EnumMember]
        NoneItem = 0x000,
        /// <summary>
        /// New item has been created
        /// </summary>
        [EnumMember]
        CreatedItem = 0x001,
        /// <summary>
        /// item Information has been updated
        /// </summary>
        [EnumMember]
        UpdatedItem = 0x002,
        /// <summary>
        /// item has been deleted
        /// </summary>
        [EnumMember]
        DeletedItem = 0x004,
        /// <summary>
        /// All item Types
        /// </summary>
        [EnumMember]
        AllItems = NoneItem | CreatedItem | UpdatedItem | DeletedItem
      }
    
      public class User : BaseDataContract
      {
    
        private String username;
        private String firstName;
        private String lastName;
        private String password;
        private String active;
        private Boolean removeAll;
        private Boolean readers;
        private Boolean writer;
        private Boolean reporter;
        private Boolean admin;
        private String fullName;
        private String emailAddress;
    
        [DataMember]
        public String Username
        {
          get { return username; }
          set { username = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public String FirstName
        {
          get { return firstName; }
          set { firstName = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public String LastName
        {
          get { return lastName; }
          set { lastName = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public String Password
        {
          get { return password; }
          set { password = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public String Active
        {
          get { return active; }
          set { active = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public Boolean Reader
        {
          get { return readers; }
          set { readers = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public Boolean Writer
        {
          get { return writer; }
          set { writer = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public Boolean Reporter
        {
          get { return reporter; }
          set { reporter = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public Boolean Admin
        {
          get { return admin; }
          set { admin = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        /// <summary>
        /// Set to true if user will be removed from all groups
        /// </summary>
        [DataMember]
        public Boolean RemoveAll
        {
          get { return removeAll; }
          set { removeAll = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public String FullName
        {
          get { return fullName; }
          set { fullName = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        [DataMember]
        public String EmailAddress
        {
          get { return emailAddress; }
          set { emailAddress = value; this.CurrentState |= DataContractState.Modified; }
        }
    
        public User()
        {
          removeAll = false;
          active = "A";
          writer = false;
          readers = false;
          reporter = false;
          admin = false;
        }
    
        public User(IDataReader reader)
        {
          username = reader[0].ToString(); //user_name
          firstName = reader[1].ToString(); //first_name
          lastName = reader[2].ToString(); //last_name
          password = reader[3].ToString(); //password
          active = reader[4].ToString(); //active
          readers = Boolean.Parse(reader[5].ToString()); //reader
          writer = Boolean.Parse(reader[6].ToString()); //writer
          reporter = Boolean.Parse(reader[7].ToString()); //reporter
          admin = Boolean.Parse(reader[8].ToString()); //admin
          fullName = reader[9].ToString(); //full_name
          emailAddress = reader[10].ToString(); //email_address
          removeAll = false;
        }
      }

     

    and my BaseDataContract:

      [DataContract, Serializable]
      public class BaseDataContract : ICloneable
      {
        private DataContractState currentState;
    
        public delegate void CurrentStateEventHandler(DataContractState state);
        public event CurrentStateEventHandler CurrentStateChanged;
    
        private bool serializing = false;
    
        /// <summary>
        /// Boolean is true if serialization is being done
        /// </summary>
        protected bool IsSerializing
        {
          get { return serializing; }
        }
    
        /// <summary>
        /// Bool holds if data column exists
        /// </summary>
        /// <param name="reader">IDataReader being passed in</param>
        /// <param name="columnName">Column Name</param>
        public bool ColumnExists(IDataReader reader, string columnName)
        {
          for (int i = 0; i < reader.FieldCount; i++)
          {
            if (reader.GetName(i) == columnName)
            {
              return true;
            }
          }
    
          return false;
        }
    
        /// <summary>
        /// The object has been modified or not
        /// </summary>
        [DataMember]
        public DataContractState CurrentState
        {
          get { return currentState; }
    
          set
          {
            if (currentState == DataContractState.Invalid || !IsSerializing)
            {
              switch (value)
              {
                // may need to add more cases
                case (DataContractState.Unchanged | DataContractState.Modified):
                  currentState = DataContractState.Modified;
                  break;
                default:
                  currentState = value;
                  break;
              }
            }
            if (this.CurrentStateChanged != null)
              this.CurrentStateChanged(value);
          }
        }
    
        /// <summary>
        /// Constructor
        /// </summary>
        public BaseDataContract()
        {
          currentState = DataContractState.Unchanged;
        }
    
        [OnDeserializing]
        private void OnDeserializing(StreamingContext context)
        {
          serializing = true;
        }
    
        [OnDeserialized]
        protected void OnDeserialized(StreamingContext context)
        {
          serializing = false;
        }
    
    
        #region ICloneable Members
    
        /// <summary>
        /// Performs a MemberwiseClone (shallow clone) on the object. Override this method to perform a deep clone in cases where you have nested objects.
        /// </summary>
        /// <returns>A new instance of the object</returns>
        public virtual object Clone()
        {
          return MemberwiseClone();
        }
    
        #endregion
      }

     

    Everything works fine when I have the client and the server on one machine. If I try to split them up and move the client onto another machine I get the error.

    Thanks in advance,

    Travis

     


    Sunday, May 15, 2011 5:35 PM

Answers

  • I figured it out... I installed the SP1 of 3.5 and it started working. Thanks for the assistance everyone!
    • Marked as answer by Spheriad Thursday, May 19, 2011 5:10 AM
    Thursday, May 19, 2011 5:10 AM

All replies

  • In your client PC, do you have .Net 3.0 or + runtime environment running. 

    And your USER class is not marked as [DATACONTRACT]... could you please add DataContract attribute to it as well. 

     

     


    Tanvir Huda Application Architect/Consultant
    Monday, May 16, 2011 12:44 AM
  • Thanks for the reply, I have .Net 3.5 installed. I have [DataContract,Serializable] in my base class that the child classes will use. Just to check I added [DataContract] and [Serializable] to the class and re-built with no luck. Any other suggestions?
    Monday, May 16, 2011 4:33 AM
  • Hello, does the problem occur on a single machine only? If you copy the client application to a third machine, does it work?
    Lante, shanaolanxing This posting is provided "AS IS" with no warranties, and confers no rights.
    Windows Azure Technical Forum Support Team Blog
    Tuesday, May 17, 2011 1:23 AM
  • I figured it out... I installed the SP1 of 3.5 and it started working. Thanks for the assistance everyone!
    • Marked as answer by Spheriad Thursday, May 19, 2011 5:10 AM
    Thursday, May 19, 2011 5:10 AM