6

Using .NET 4/C#...

I need to deserialize old config files that contain the serialized representation of a type named, say, ns1.X . The serialization has been done using BinaryFormatter.

The problem is, after a round of refactoring, the type X has been moved to a different namespace, say ns2.X .

I have tried creating a new empty ns1.X type that derives from ns2.X, and while this circumvents the 'Can't find type ns1.X' error, the properties in the deserialized object are all null. Also, no ctors get called in the process.

Any suggestions?

Cristian Diaconescu
  • 34,633
  • 32
  • 143
  • 233
  • 1
    Not sure if this can solve your problem since I never actually used it, but I remember reading up on TypeForwarding some time ago: you can find the info here: http://msdn.microsoft.com/en-us/library/ms404275.aspx – Anton Oct 12 '11 at 14:07
  • Interesting. I'll check it out. – Cristian Diaconescu Oct 12 '11 at 14:43
  • A Google search found this which might help: http://www.codeproject.com/KB/cs/DrawWithMouse.aspx#AdvancedBinarySerialization:DeserializinganObjectIntoaDifferentTypeThantheOneItwasSerializedInto9 – Dan Oct 12 '11 at 14:45

1 Answers1

1

You're going to need to use an ISerializationSurregate to make this happen. It's not too difficult and Jeff Richter explains it really well. I recommend his book CLR Via c# 3.

Kell
  • 3,252
  • 20
  • 19