I'm trying to implement some CSLA objects along with the Sterling DB project and having some troubles plugging in the MobileFormatter as a custom Serializer. I'm pretty sure I'm just getting the syntax wrong. I can do this:
Save:
IsolatedStorageSettings.ApplicationSettings["Test"] = MobileFormatter.Serialize(dataToCache);
Retrieve:
var test = MobileFormatter.Deserialize((byte[])IsolatedStorageSettings.ApplicationSettings["Test"]) as EpmCacheLookupData;
Just fine however to integrate I have to plug the Deserialize step into the method below where the BinaryReader is used to return the isolated storage data. I can't get the syntax right to create my type based on it being dynamically supplied as Type type nor can I get the data to deserialize correctly. It is either missing bits and pieces or I'm not grabbing it correctly.
public override object Deserialize(Type type, BinaryReader reader)
{
var buffer = new byte[reader.BaseStream.Length];
reader.Read(buffer, 0, (int)reader.BaseStream.Length);
fails here:
var obj = MobileFormatter.Deserialize(buffer) ;
if it did work I just have an obj not a MyBusinessClass.
}
thanks
jack
The MobileFormatter has rather strict rules about what it can serialize/deserialize. Are you sure your classes follow these rules?
"Normal" .NET types can't be serialized by MobileFormatter (other than primitive types), so you must either subclass something like MobileObject or MobileList, or implement IMobileObject manually.
Rocky,
The object I'm trying to serialize is a BusinessBase class and per my example I can serialize/deserialize it from Isolated Storage on my own just fine. My problem I believe is the syntax using it within the Sterling DB framework's method. My test is essentially grabbing it from the dataPortal fetch and caching it with SterlingDB, and then trying to read it out again.
The SterlingDB method is presenting the Type and an open BinaryReader. I'm still trying to confirm if 100% of the stream is my object or if I'm somehow suppose to know how much to read (some of the examples suggest as much). I made the assumption that 100% of the stream is my object but I'm still getting stuck.
Thanks, especially since I'm sure you are busy at Mix.
jack
Copyright (c) Marimer LLC