I want to save my object to hard disk (like cache) with XmlSerializer. In this case, I don\'t have any problem.
However, when I want to deserialize thi
you can use SerializationHelper.DeSerializeNow as described in my post: http://borismod.blogspot.com/2008/07/nunit-serialization-test.html
internal class SerializationHelper
{
private static readonly string DefaultFilePath = "test.dat";
internal static void SerializeNow(object c)
{
SerializeNow(c, DefaultFilePath);
}
internal static void SerializeNow(object c, string filepath)
{
FileInfo f = new FileInfo(filepath);
using (Stream s = f.Open(FileMode.Create))
{
BinaryFormatter b = new BinaryFormatter();
b.Serialize(s, c);
}
}
internal static object DeSerializeNow()
{
return DeSerializeNow(DefaultFilePath);
}
internal static object DeSerializeNow(string filepath)
{
FileInfo f = new FileInfo(filepath);
using (Stream s = f.Open(FileMode.Open))
{
BinaryFormatter b = new BinaryFormatter();
return b.Deserialize(s);
}
}
}