CSLA Light Serialization Woes

CSLA Light Serialization Woes

Old forum URL: forums.lhotka.net/forums/t/8242.aspx


solidgranite posted on Wednesday, December 30, 2009

Hi All

I've encountered a roadblock with CSLA Light.

I need to serialize a dictionary (inside a Criteria object (I'm using it to store column/values for SQL filter) from CSLA Light to CSLA.NET. I've used Paul Welter's XML Serializable Generic Dictionary for this purpose (http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx)

I've read in Rocky's book that WCF provides NetDataContractSerializer so that an exact clone of the original object graph can be sent over the wire. It suggests I use the UseNetDataContract attribute provided by CSLA to tell WCF to use this alternative serializer.

Problem is that MobileFormatter uses DataContractSerializer and hence my serializable dictionary isn't serialized correctly.

I'm clearly missing something. How are other people storing values for their SQL column filters in their Criteria objects so that they can be successfully serialized from Silverlight to .NET?

Thanks in advance!

Paul

RockfordLhotka replied on Saturday, January 02, 2010

MobileFormatter sort of uses the DCS, but first it converts your object model into a set of data transfer objects. This is necessary, because there's no workable private reflection in Silverlight, so it isn't normally possible to serialize private field values in objects.

I have some blog posts on this topic, which you can find from the FAQ

http://www.lhotka.net/cslanet/faq/SilverlightFaq.ashx

In the end this means that MobileFormatter only works with primitive values, values we special-cased (like Decimal, Guid, etc) and types that implement Csla.Core.IMobileObject.

Because it can be hard to implement IMobileObject correctly, there are several base types in Csla.Core that already do the work for you, including MobileObject, MobileList and MobileDictionary.

You may be able to use MobileDictionary for your purposes - or at least use its code as a template to enhance your existing dictionary type so it implements IMobileObject.

solidgranite replied on Wednesday, January 06, 2010

Hi Rocky

Thanks for the information about the Csla.Core classes.

MobileDictionary did the trick!

Cheers

Paul

Copyright (c) Marimer LLC