Possible Duplicate:
Serialize a Bitmap in C#/.NET to XML
I'm trying to serialize MyClass by using XmlSerializer, but looks like [XmlInclude(typeof(Bitmap))] doesn't works.
using System;
using System.Drawing;
using System.IO;
using System.Xml.Serialization;
class Program {
static void Main() {
var myClass = new MyClass {
Name = "foo",
MyImage = new Bitmap(@"e:\pumpkin.jpg")
};
var serializer = new XmlSerializer(typeof(MyClass));
var fileStream = File.OpenWrite(@"e:\test.xml");
serializer.Serialize(fileStream, myClass);
}
}
[Serializable]
[XmlInclude(typeof(Bitmap))]
public class MyClass {
public string Name { get; set; }
public Bitmap MyImage { get; set; }
}
This is the resulting file:
<?xml version="1.0"?>
<MyClass xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Name>foo</Name>
<MyImage>
<Palette />
</MyImage>
</MyClass>