Hi Fred,
you could also use a SerializationBinder to define which type will be loaded in the case that another type is being deserialized:
public sealed class Version1ToVersion2DeserializationBinder : SerializationBinder
{
public override Type BindToType(string assemblyName, string typeName)
{
Type typeToDeserialize = null;
if (typeName == "OldClassName")
typeName = "NewClassName";
typeToDeserialize = Type.GetType(String.Format("{0}, {1}",
typeName, assemblyName));
return typeToDeserialize;
}
}
To deserialize, you just have to set the Binder Property of the BinaryFormatter:
formatter.Binder = new Version1ToVersion2DeserializationBinder();
NewClassName obj = (NewClassName)formatter.Deserialize(fs);
Regards
Lumo