.NET, Why must I use *Specified property to force serialization? Is there a way to not do this?

TheDevOpsGuru picture TheDevOpsGuru · Jul 15, 2011 · Viewed 12.2k times · Source

I am using xml-serialization in my project to serialize and deserialize objects based on an xml schema. I used the xsd tool to create classes to use when serializing / deserializing the objects.

When I go to serialize the object before sending, I am forced to set the *Specified property to true in order to force the serializer to serialize all propeties that are not of type string.

Is there a way to force the serialization of all properties without having to set the *Specified property to true?

Answer

Thomas Levesque picture Thomas Levesque · Jul 18, 2011

The FooSpecified property is used to control whether the Foo property must be serialized. If you always want to serialize the property, just remove the FooSpecified property.