Answered Exception when trying to serialize an object

  • Sunday, December 09, 2012 11:22 PM
     
      Has Code

    I have a problem serializing this object, I isolated the property that is causing the problem.

    I'm trying to serialize this RetrieveDataResp class. it looks like the following

      [Serializable]
        [XmlRoot("retrieveDataResp")]
        public class RetrieveDataResp
        {
            //Other stuff
    
            [XmlElement("response")]
            public Response.Response XmlResponse { get; set; }
            
        }

    Response class looks like the following

    public class Response
        {
    
            /// <summary>
            /// This is a bool that will be set if something when wrong
            /// with the request
            /// </summary>
            [XmlElement("withError")]
            public bool WithError { get; set; }
    
            /// <summary>
            /// This is a string that will save the exception message
            /// so the UI will be able to display the ex. message.
            /// </summary>
            [XmlElement("exceptionString")]
            public string ExceptionString { get; set; }
    
            /// <summary>
            /// This is the response type
            /// </summary>
            [XmlElement("responseType")]
            public string ResponseType { get; set; }
        }

    I would like the xml to look like this

    <retrieveDataResp>

        <response>

            <withError>false</withError>

            <exceptionString />

            <responseType>Retrieve Data</responseType>

        </response>

    </retrieveDataResp>

    Thanks a lot guys

All Replies

  • Monday, December 10, 2012 12:47 AM
     
     

    I also tried to add "[XmlRoot("response")] on top of the Response class (I don't think I need though, in fact i think that's even wrong), but that did not work either. I can't think of anything that it throwing the exception while serializing,

    The exception is "There was an error reflecting type "...

  • Monday, December 10, 2012 2:06 AM
     
     Answered

    I figured it out. The Response class needs to have an empty constructor!

    Thanks anyways

    • Marked As Answer by raac130 Monday, December 10, 2012 2:06 AM
    •  
  • Tuesday, December 11, 2012 1:23 AM
    Moderator
     
     

    Hi Raac130,

    Glad to know your problem is solved. Thank you for sharing.

    Have a nice day.


    Alexander Sun [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.