views:

391

answers:

1

I have an inherited code base that was developed in .NET 1.1. When I migrated it to 2.0, I renamed an assembly. Now, I find that it will be necessary to read old files containing objects serialized by the old assembly and .NET 1.1. Some fields are successfully deserialized, but most are ignored. If I enable FormatterAssemblyStyle.Full , I get an error such as:

Member 'T_VERSION+s_sys_ver' in class 'MyNamespace.T_VERSION' is not present in the serialized stream and is not marked with System.Runtime.Serialization.OptionalFieldAttribute.

An examination of the binary file shows that T_VERSION+s_sys_ver is present in some form, and the field type hasn't changed.

Is there any way to deserialize the old format files short of manually reverse engineering the old format and writing my own manual deserialization routine?

+4  A: 

Check SerializationBinder

During serialization, a formatter transmits the information required to create an instance of an object of the correct type and version. This information generally includes the full type name and assembly name of the object. The assembly name includes the name, version, and strong name (see Strong-Named Assemblies) hash of the assembly. By default, deserialization uses this information to create an instance of an identical object (with the exception of any assembly loading restricted by the security policy). Some users need to control which class to load, either because the class has moved between assemblies or a different version of the class is required on the server and client.

eglasius