Can XmlSerializer deserialize into a Nullable?

I think you need to prefix the nil=”true” with a namespace in order for XmlSerializer to deserialise to null. MSDN on xsi:nil <?xml version=”1.0″ encoding=”UTF-8″?> <entities xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:type=”array”> <entity> <id xsi:type=”integer”>1</id> <name>Foo</name> <parent-id xsi:type=”integer” xsi:nil=”true”/>

Why doesn’t the conditional operator correctly allow the use of “null” for assignment to nullable types? [duplicate]

This doesn’t work because the compiler will not insert an implicit conversion on both sides at once, and null requires an implicit conversion to become a nullable type. Instead, you can write task.ActualEndDate = TextBoxActualEndDate.Text != “” ? DateTime.Parse(TextBoxActualEndDate.Text) : new DateTime?(); This only requires one implicit conversion (DateTime to DateTime?). Alternatively, you can cast … Read more

Serializing a Nullable in to XML

If you just want it to work, then perhaps: using System; using System.ComponentModel; using System.Xml.Serialization; public class Account { // your main property; TODO: your version [XmlIgnore] public Nullable<DateTime> AccountExpirationDate {get;set;} // this is a shim property that we use to provide the serialization [XmlAttribute(“AccountExpirationDate”)] [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public DateTime AccountExpirationDateSerialized { get {return AccountExpirationDate.Value;} set … Read more