XML serialization of hash table(C#3.0)
Posted
by Newbie
on Stack Overflow
See other posts from Stack Overflow
or by Newbie
Published on 2010-05-27T02:52:56Z
Indexed on
2010/05/27
3:01 UTC
Read the original article
Hit count: 156
c#3.0
Hi I am trying to serialize a hash table but not happening
private void Form1_Load(object sender, EventArgs e)
{
Hashtable ht = new Hashtable();
DateTime dt = DateTime.Now;
for (int i = 0; i < 10; i++)
ht.Add(dt.AddDays(i), i);
SerializeToXmlAsFile(typeof(Hashtable), ht);
}
private void SerializeToXmlAsFile(Type targetType, Object targetObject)
{
try
{
string fileName = @"C:\testtttttt.xml";
//Serialize to XML
XmlSerializer s = new XmlSerializer(targetType);
TextWriter w = new StreamWriter(fileName);
s.Serialize(w, targetObject);
w.Flush();
w.Close();
}
catch (Exception ex) { throw ex; }
}
After a google search , I found that objects that impelment IDictonary cannot be serialized. However, I got success with binary serialization.
But I want to have xml one. Is there any way of doing so?
I am using C#3.0
Thanks
© Stack Overflow or respective owner