0
votes

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 solving 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.

2

2 Answers

2
votes

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.

0
votes

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.