Deserialize to enter whose namespace has changed

Using .NET 4 / C # ...

I need to deserialize old configuration files containing a serialized representation of a type named, say, ns1.X. Serialization is performed using the BinaryFormatter .

The problem is that after the refactoring round, type X was moved to another namespace, for example ns2.X.

I tried to create a new empty type ns1.X that comes from ns2.X, and although it bypasses the error β€œCannot find type ns1.X”, the properties in the deserialized object are all null . In addition, calls are not called during the call.

Any suggestions?

+6
source share
1 answer

You will need ISerializationSurregate for this to happen. It's not too complicated, and Jeff Richter explains it very well. I recommend his book CLR Via C # 3.

+1
source

Source: https://habr.com/ru/post/899132/


All Articles