Can't cache object in isolated storage cache when using [DataContract(IsReference=true)]

Topics: Caching Application Block , Silverlight Integration Pack
Feb 3, 2012 at 1:07 PM
Edited Feb 3, 2012 at 1:10 PM

Does anyone know if this should be possible using the Silverlight Integration Pack?

If I try and store the object now exception is thrown but the object isn't added to the cache. If I then remove IsReference=true then object is stored in the cache.

Thank you in advacne for any help.

Feb 6, 2012 at 7:27 AM

Is the following correct?  You are making a call to a WCF service that has DataContact(IsReference=true) set. You are calling the WCF service which returns the object in Silverlight but when you attempt to add the object to the Enterprise Library Isolated Storage Cache you get an exception. 

What exception are you receiving?  What serialization are you using with the WCF service?

I suspect you have circular references which are causing the DataContractJsonSerializer to throw an exception. 

Randy Levy
Enterprise Library support engineer 

Feb 6, 2012 at 8:20 AM

All of the above is correct. The data is hierarchical with parent/child references.

I have investigated this further and it is the Json serializer throwing an exception (sorry don't have exact error just now)

Is it possible to use a different serializer other than the Json one?

Feb 7, 2012 at 2:52 AM
Edited Feb 7, 2012 at 2:54 AM

Yes you can use a different serializer.  You will have to write your own serializer that implements the IIsolatedStorageCacheEntrySerializer interface.  

Actually, it doesn't look too bad.  I think you can just extend the existing IsolatedStorageCacheEntrySerializer class and override the two virtual methods SerializeObject and DeserializeObject with your own serialization implementation.

Then it's a simple matter (famous last words!?) of configuring Enterprise Library (using the config file or the fluent interface) to use your custom serializer.

Randy Levy
Enterprise Library support engineer