Serializing types

JCDenton

Newcomer
Joined
Feb 3, 2005
Messages
10
Attempting to serialize all the type information contained in an assembly. To test my code I'm using a SharpDevelop assembly. However, when running:

Code:
StringWriter sw = new StringWriter();
XmlSerializer XmlSer = new XmlSerializer(typeof (Type[]));
XmlSer.Serialize(sw, TargetAss.GetTypes());

The code breaks with error
Code:
{"There was an error generating the XML document."}

{"Cannot serialize interface ICSharpCode.SharpDevelop.Gui.ICanBeDirty."}

Why would it try to serialize interface ICanBeDirty ? All I need of the Type is MethodInfo, properties, etc.

Thanks all
 
Cannot serialize types in XML

This is a quirk of XML serialization - it cannot serialize types. Just try and serialize any type using the XmlSerializer and you will get an exception of some sort.

The only solution is to represent each type in some other form (e.g. string), or use a different serialization formatter.

Good luck :cool:
 
Back
Top