Is there a way to serialize a CodeCompileUnit object as XML.
The problem is that:
XmlSerializer xml = new XmlSerializer( typeof(CodeCompileUnit) );
throws the following exception:
"Cannot serialize member System.CodeDom.CodeObject.UserData of type System.Collections.IDictionary, because it implements IDictionary."
XmlSerializer has issues with IDictionary. It is now deprecated in favor of DataContractSerializer which can serialize a CodeCompileUnit instance:
var serializer = new DataContractSerializer(typeof(CodeCompileUnit));
serializer.WriteObject(Console.OpenStandardOutput(), new CodeCompileUnit());
This is a limitation of the XML serializer : dictionaries can't be serialized (even though I don't see any good reason why). Actually they can be serialized if they implement IXmlSerializable (which, by the way, is a real pain to implement), but that's not the case for the UserData property... so you're stuck
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With