CSLA4 SL: MobileDictionary crashes when keys are business objects

CSLA4 SL: MobileDictionary crashes when keys are business objects

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


Cuong posted on Wednesday, January 26, 2011

Hi Rocky,

I use MobileDictionary like below. Please notice the class Key drives from ReadOnlyBase.

[Serializable]
public class Data : ReadOnlyBase<Data>
{
        public static PropertyInfo<MobileDictionary<Key, string>> DicProperty = RegisterProperty<MobileDictionary<Key, string>>(x => x.Dic);
        public MobileDictionary<Key, string> Dic
        {
            get
            {
                var value = ReadProperty(DicProperty);
                if (value == null)
                {
                    value = new MobileDictionary<Key, string>();
                    LoadProperty(DicProperty, value);
                }
                return value;
            }
        }
...

}

When I run the app and get Data from the server the app throws an exception:

System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at Csla.Core.MobileDictionary`2.Csla.Serialization.Mobile.IMobileObject.SetChildren(SerializationInfo info, MobileFormatter formatter)
   at Csla.Serialization.Mobile.MobileFormatter.DeserializeAsDTO(List`1 deserialized)
   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(List`1 data)
   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(XmlReader reader)
   at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream)
   at Csla.DataPortalClient.WcfProxy`1.proxy_FetchCompleted(Object sender, FetchCompletedEventArgs e)

 

I created a sample to illustrate the issue. You can download it from the link

http://www.mediafire.com/?wrin747gca2lx2a

 

RockfordLhotka replied on Wednesday, January 26, 2011

That isn't a supported scenario, sorry.

Copyright (c) Marimer LLC