I have a class I serialize to a file, ie. myfile01.myfile. I’m using binary serialization (not xml).
In version 1 of this class, there was a field ‘ColoredFont’. This is a class that contains a Font and a Color.
In version 2 of the class, the class ColoredFont was changed, and the ‘Font’ field was replaced by ‘SerializableFont’.
Now the problem: when i want to open version 1 files, I get an error :
Object of type 'System.Drawing.Font' cannot be converted to
type 'Project.SerializableFont'.
I already use a custom serialization binder
public class Binder : SerializationBinder {
public override Type BindToType(string assemblyName, string typeName) {
Type tyType = null;
string sShortAssemblyName = assemblyName.Split(',')[0];
Assembly[] ayAssemblies = AppDomain.CurrentDomain.GetAssemblies();
if (sShortAssemblyName.ToLower() == "project"
|| sShortAssemblyName == "SoftwareV_3.0" )
{
sShortAssemblyName = "SoftwareV_4.0";
}
foreach (Assembly ayAssembly in ayAssemblies) {
if (sShortAssemblyName == ayAssembly.FullName.Split(',')[0]) {
tyType = ayAssembly.GetType(typeName);
break;
}
}
return tyType;
}
}
How I can tell the deserialization to convert System.Drawing.Font to SerializableFont ??
Try this for the
ColoredFontclass :