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.

4

1 回答 1

0

是不是被持久化的对象使用的是旧的类结构,而你添加的属性是必需属性,导致反序列化失败?

此外,如果 Serializable 属性存在并且您不确定它为什么存在,那么验证其他代码是否没有使用此类进行序列化可能是个好主意 - 如果是,您添加的新属性可能会破坏它:)

希望这可以帮助!

于 2012-09-10T07:34:19.513 回答