开发者

AppFabric serialization problem

I am trying cache a class instance with AppFabric but it return class instance with empty members. The reason is DataContract Attribute. My class is marked with [Serializable] and [DataContract(Name = "TestClass", Namespace = "CustomNameSpace.TestClass")] attributes.

Problem solv开发者_开发技巧ing if I mark all properties with DataMember or remove DataContract attribute.

But I do not want to remove DataContract attributte because of other serialization needs (such as json or something else) Or I do not want to add DataMember attribute to other classes. (a lot of)

Do you have any idea to solve that problem ?

Thanks.


The rules of the serialization engine prefere DataContractAttribuee serialization to legacy SerializableAttribute. Since you've marked your class with DataContractAttribute it's going to try to use DCS. Having the DataContractAttribute on your class without specifying any DataMemberAttributes to your properties is completely useless and, as you can see, is just hurting you because the serialization engine expects you to follow the rules.

Your only options to get this to work are to either apply the corresponding DataMemberAttributes to your properties or remove the DataContractAttribute.


in my classes i have just used the [Serializable] attribute on the class, nothing on the members. it works like a charm with appfabric cache.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜