Why isn’t XmlSerializer serializing my object/properties?

I recently ran into an issue that was pretty obvious in retrospect.  However, I spent about an hour figuring out why in the world the XmlSerializer wasn’t serializing my seemingly good object and the properties within it.  All of the properties on the object were public, and when I had stepped through the code with the debugger, there were values (that I expected) visible within the object.

Well, it seems that a setter is required in order for the XmlSerializer class to serialize the property.  This makes fairly good sense, because you usually wouldn’t want to serialize an object without a way to deserialize it.  In my case, however, serialization was enough, as I was not planning on deserializing this object.  So, sure enough, after adding a setter for all of my properties, XmlSerializer correctly serialized my object as I had wanted it to in the beginning.

Tags: , ,

This entry was posted on Monday, August 24th, 2009 at 2:43 am and is filed under .NET Framework, C#. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.