I have a doubt in serialization.
example:
interface IBase {}
[DataContract]
class Base : IBase
{
[DataContract]
public Derived Child{get;set;}
}
[DataContract]
[KnownType(typeof(Base))]
class Derived : Base
{
[DataMember]
public IBase Parrent {get;set;}
}
If I try to store an instance of Base class in IsolatedStorage, it is not getting executed; it hangs. Is there any way to do this ?
Well, your attributes are all over the place –
Base.Childis a[DataMember], not a[DataContract]. IIRC in phone 7 you need public types for serialization; and it is the base that needs informing of children. However; theIBaseis another problem; that isn’t designated as a contract. If possible, change that toBase(notIBase), as the serializer needs to know about all concrete contracts.So:
Additionally, a
Parentmember is a big problem for tree serializers (andDataContractSerializeris a tree serializer, unless you explicitly enable full-graph mode).You might be able to get DCS to like
IBase, but you’d need to investigate marking that as a contract and noting the concrete types. If you can’t get anywhere with that, I know protobuf-net supports that layout (although I haven’t tested that specifically for phone 7, but there is no fundamental reason it can’t work).