Search code examples
c#appfabric

AppFabric Cache - issue with Get


I have two client applications connecting to an Windows Server AppFabric Cluster (there is only one node). Client 1 Puts an object which has a datetime field to Cache (All entities are defined in a different C# class library project). When I Get this object through Client 1, everything looks good, however when I retrieve the same object through Client 2, I get the datetime field set to 01-01-0001 00:00:00 all the time. However, if I decorate the DateTime field with [DataMember] attribute, it works fine. Could someone please tell me what is going on?

Update: Client1 is a WCF service, and Client 2 is an ASP.NET application. Framework used is 4.0.


Solution

  • AppFabric serializes the type (using NetDataContractSerializer). If that type is decorated with [DataContract], then only the members marked with [DataMember] will be serialized. If the type is not decorated with [DataContract], then IIRC it defaults to BinaryFormatter behaviour, i.e. serializing the fields - it may or may not want [Serializable] in this case.

    So: it sounds like the type is a data-contract so yes; you'll need to mark it [DataMember] - otherwise it will assume the all-zero value (DateTime.MinValue, aka 01-01-0001 00:00:00)