5

I'm trying to save two Lists of objects in the phone ApplicationSettings, but I'm stuck at a strange issue (But it's probably me making a silly mistake somewhere).

If I only save one of the lists, it works as supposed - It'll save it, and reload it when app is launched next time. But if I try to save 2 lists, none of them seem to be saved correctly. No errors or anything, just "blankness".

See code below.

//My save method
public void Gem()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;

            if (settings.Contains(INDTASTNINGER_LIST))
            {
                settings[INDTASTNINGER_LIST] = _indtastningsListe;
            }
            else
                settings.Add(INDTASTNINGER_LIST, _indtastningsListe);

            if (settings.Contains(INDTASTNINGER_LIST2))
            {
                settings[INDTASTNINGER_LIST2] = _indtastningsListe2;
            }
            else
                settings.Add(INDTASTNINGER_LIST2, _indtastningsListe2);
            settings.Save();
        }

        //Constructor supposed to load settings
        public Indtastninger()
        {
            var settings = IsolatedStorageSettings.ApplicationSettings;

            if (settings.Contains(INDTASTNINGER_LIST))
            {
                _indtastningsListe = null;
                _indtastningsListe = (List<Indtastning>)settings[INDTASTNINGER_LIST];
            }
            if (settings.Contains(INDTASTNINGER_LIST2))
            {
                _indtastningsListe2 = null;
                _indtastningsListe2 = (List<Indtastning>)settings[INDTASTNINGER_LIST2];
            }
        }

What am I doing wrong? If I comment out the part with "list2" stuff, the first one will be saved/retrieved perfectly.

David K
  • 3,153
  • 5
  • 18
  • 27
  • And perhaps I should add that it makes no difference which list I comment out. Still success with one, but with two, nothing is saved/retrieved. – David K Aug 03 '11 at 20:14
  • What version of the SDK are you using? I can't seem to repro this on the RC. – Den Aug 03 '11 at 22:02
  • What if you add a `settings.Save()` between the adds. It could be that serialization of the second list is breaking and not calling the `save()` – Chris Sainty Aug 03 '11 at 23:18
  • I'm using Mango. I tried putting in extra .save's but no result. – David K Aug 04 '11 at 06:22
  • Mango is still beta you could try the same thing on a non-Mango machine... – Emond Aug 04 '11 at 06:44
  • Yeah I guess, but my app is for mango phones so I'm hoping theres a fix for this somewhere. – David K Aug 04 '11 at 07:23
  • As per your previous comment, could be related to Mango. Following could be worth a shot: config.Save(ConfigurationSaveMode.Modified); Set the mode whilst saving... – TheRRRanger Aug 15 '11 at 01:00
  • I also tried to repro on the RC with no issues. Can you post a code sample somewhere that repros your issue so we can have a look? – Chris Koenig Aug 15 '11 at 07:33

1 Answers1

2

I have faced the same issue some time ago, the problem is that you only can save on the IsolatedStorage objects that are XML serializables.

if you save other object, it will work even with the debugger but when the app is restarted, all the saved data is lost.

Ariel
  • 1,641
  • 1
  • 18
  • 27