Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Attempting to serialize all the type information contained in an assembly. To test my code I'm using a SharpDevelop assembly. However, when running:

 

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

 

The code breaks with error

{"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

  • 2 weeks later...
Posted

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:

Never trouble another for what you can do for yourself.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...