Expanding on the comment:
I think the issue is that you're creating the XmlSerializer
with typeof(object)
.
If you use either of the following it should work:
XmlSerializer xs = new XmlSerializer(myDynamicType);
XmlSerializer xs = new XmlSerializer(instance.GetType());