0

I am using the DataContractSerializer to persist objects. Most classes have the [DataContract] attribute but one (not sure why) has [Serializable]. The properties of this class have the [DataMember] attribute. So far, it has worked ok.

Recently, I tried to add a new property but get an error when deserialising. The error message is something like: 'property Notes was expected but found property ModuleNr'.

I tried adding the [DataContract] attribute but got a different error like: 'Deserialised object with id 15 not found'. It seems that the class is not being deserialised at all.

Can anyone explain what I am doing wrong and what I can do to deserialise the existing objects.

Thanks.

paul
  • 13,312
  • 23
  • 81
  • 144

1 Answers1

0

Is it the case that the object that was persisted was using the older class structure, and the property you added is a required property, causing the deserialization to fail?

Also, if the Serializable property is there and you are not sure why its there, it might be a good idea to verify if some other code is not using this class to serialize - if it is, the new property you are adding might break it :)

Hope this helps!

merlinbeard
  • 218
  • 1
  • 3
  • 14
  • Thanks. I add the new property with the attribute parameter 'IsRequired=false'. I am also not aware of any other use of the class. It is called when the app starts up and loading the persisted objects is the first action. – paul Sep 10 '12 at 08:35