CSLA for Silverlight - MobileDictionary serialization error

CSLA for Silverlight - MobileDictionary serialization error

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


Ash002 posted on Tuesday, March 03, 2009

Error when serialising a MobileDictionary from Silverlight client to server.

    private static PropertyInfo<MobileDictionary<string, string>> _Test =
      RegisterProperty<MobileDictionary<string, string>>(typeof(ReportViewerRequest), new PropertyInfo<MobileDictionary<string, string>>("Test")) ;

    public MobileDictionary<string, string> Test
    {
      get { return GetProperty(_Test); }
      set { SetProperty(_Test, value); }
    }

    // Silverlight data portal method
    public void Child_Create()
    {
         LoadProperty(_Test, new MobileDictionary<string, string>()); 
         Test["test"] = "hello dictionary";


Error:
The constructor to deserialize an object of type 'Csla.Core.MobileDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' was not found.

thrown by ObjectManager.GetConstructor(Type t, Type[] ctorParams)

We also revived our own mobile dictionary class, pre csla's. This class suffered the same error. Attempted to fix as per http://www.peterguy.com/archives/2007/04/serializing_a_g.html, by providing the missing constructor, but suceeded only in crashing vs.

Thanks

Ashley








RockfordLhotka replied on Wednesday, March 04, 2009

Thanks, I'll take a look. If you figure out an answer in the meantime, please let me know!

mamboer replied on Tuesday, March 17, 2009

I got the same error when tried to pass a MobileDictionary<string,object> instance from SL client to server.It seems that the BinaryFormatter of System.RunTime can't deserialize it correctly,while the MobileFormatter can~~


mamboer replied on Tuesday, March 17, 2009

BTW:
   When doing deserialization on a MobileDictionary instance using MobileFormatter,its keys and values disappear

RockfordLhotka replied on Tuesday, March 17, 2009

Oh, that makes a little more sense to me then. I haven’t had time to look into this – but it seemed odd that the MF couldn’t serialize it from a SL client to .NET server, since I have unit tests using the MF.

 

I don’t have any tests using the BF or NDCS though, and if I understand correctly you are saying that one or both of these formatters is where the problem occurs.

 

Rocky

 

 

From: mamboer [mailto:cslanet@lhotka.net]
Sent: Tuesday, March 17, 2009 10:11 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] CSLA for Silverlight - MobileDictionary serialization error

 

I got the same error when tried to pass a MobileDictionary<string,object> instance from SL client to server.It seems that the BinaryFormatter of System.RunTime can't deserialize it correctly,while the MobileFormatter can~~




mamboer replied on Tuesday, March 17, 2009

I'v reconfirmed my unit tests,the conclusions are:
1,MobileDictionary instances can be serialized by both of BF and MF,

but,
2,BF can't deserialize them.(throws exception)
3,MF can deserialize them,but not correctly.(data lost)

On options 3,i pass a MobileDictionary instance from SL client to server,it becomes a blank new instance when come to the server side.
 

mamboer replied on Tuesday, March 17, 2009

@Rocky,

  I found someone had provided a serializable dictionary,it can be serialized/deserialized by BF,XmlSerializer,etc,but it's a pity that it doesn't work with our Csla's MobileFormatter. Maybe you can find sth useful on that implementation~

  http://blogs.microsoft.co.il/blogs/applisec/archive/2008/02/23/serializable-dictionary.aspx

RockfordLhotka replied on Tuesday, March 17, 2009

I fixed the BF issue, and the fix is in svn – that was easy.

 

I don’t have replication of an issue with the MF at this time. My unit tests appear to serialize/deserialize the dictionary without data loss.

 

When you observe this data loss, is it with <primitive, primitive>, <primitive, IMobileObject>, <IMobileObject, primitive> and/or <IMobileObject, IMobileObject>? I have unit tests for all these scenarios – but it would help narrow my research if I know which scenario (or all?) is problematic.

 

Rocky

 

 

From: mamboer [mailto:cslanet@lhotka.net]
Sent: Tuesday, March 17, 2009 9:31 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: CSLA for Silverlight - MobileDictionary serialization error

 

@Rocky,

  I found someone had provided a serializable dictionary,it can be serialized/deserialized by BF,XmlSerializer,etc,but it's a pity that it doesn't work with our Csla's MobileFormatter. Maybe you can find sth useful on that implementation~

  http://blogs.microsoft.co.il/blogs/applisec/archive/2008/02/23/serializable-dictionary.aspx


mamboer replied on Tuesday, March 17, 2009

I noticed your fix an hour ago,now MF works like a charm~Thanks so much.

On the data lost,sorry that it's my careless mistake,and i've found the reason now,the fact is that,

I defined a custom Criteria(inheritted from CriteriaBase) containing a property of MobileDictionary<string,object> type,but didn't override OnGetState correctly~

With a little fix,i now can pass a custom criteria with a MobileDictionary<string,object> from SL client to server!!That's what i need! Cheers!

I will add a new post to show my fruit. 

Copyright (c) Marimer LLC