Why is isolated storage not persisting in my WP7 application?

陌路散爱 提交于 2019-12-07 05:34:25

I see some issues:

  1. The IsolatedStorageSettings doc explicitly says not to call Save() because it's not thread safe (scroll down to the platform notes for WP) and may raise an exception (and cause your settings not to be saved).

  2. It seems not to be the case here, but using the string "myObjList" all around is pretty dangerous as it's easy to mispell. I would put it inside a constant and rule out any typing error

  3. In my experience IsolatedStorageSettings is not very robust on the current WP7 version. You better create a class and serialize it into an IsolatedStorage file. Anyways going on with your app you will probably have more things to save and you will have cleaner code that way.

Is your class myObj Serializable? From experience if it's not then no error will be thrown it simply isn't added to IsolatedStorage.

You can use the DataContract and DataMember attributes in your class to enable this as follows.

[DataContract]
public class myObj
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public string Id { get; set; }

    [DataMember]
    public string Phone { get; set; }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!