Xml serializer and nullable types -
06-21-2006
, 10:26 AM
Using nullable types with the XmlSerializer doesn't seem to work properly when
deserialing an object containing a propertynameSpecified for the nullable
type.
The propertynameSpecified flag simply doesn't get set by the deserializer if
the nullable type property contains a value. Can anybody explain this ?
The following example demonstrates the problem
XmlSerializer xs = new XmlSerializer(typeof(valueclass));
MemoryStream ms = new MemoryStream();
valueclass c = new valueclass();
c.NullableValue = 10;
c.NullableValueSpecified = true;
xs.Serialize(ms, c);
ms.Position = 0;
c = (valueclass)xs.Deserialize(ms);
//c.NullableValueSpecified should equal true but equals false
MessageBox.Show(c.NullableValue.ToString()+"
"+c.NullableValueSpecified.ToString());
public class valueclass
{
public int? NullableValue;
[System.Xml.Serialization.XmlIgnore()]
public bool NullableValueSpecified;
}
regards
Per Millard
Systems architect |