Ok, solved! This is a two-part solution:
1) Enabling diagnostics
First, in Visual Studio 2012 (or perhaps more correctly in .NET 4.5), it's not enough to set the following in the app.config for XmlSerialization diagnostic:
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="1" />
</switches>
</system.diagnostics>
<system.xml.serialization>
<xmlSerializer tempFilesLocation="c:\foo"/>
</system.xml.serialization>
You also need to add the attribute useLegacySerializerGeneration="true"
to produce the auto-generated .cs file of the serializer
<system.diagnostics>
<switches>
<add name="XmlSerialization.Compilation" value="1" />
</switches>
</system.diagnostics>
<system.xml.serialization>
<xmlSerializer tempFilesLocation="c:\foo" useLegacySerializerGeneration="true"/>
</system.xml.serialization>
2) Pitfall in IXmlSerializable implementation
Make sure that XmlReader (when it's in the ReadXml(XmlReader reader)
method of IXmlSerializable
) is on the StartElement of the next element when you're done with it, not on the EndElement. In other words, make sure to call:
reader.ReadEndElement();
Because of it, xml deseralization reader got skewed data and read all the elements in the wrong places, producing nulls.