Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

windows phone 8, applicationsettings not persisted

I have the following strange behaviour in my Windows phone 8, C# App.

I am saving a Setting with:

private void SaveProperty<T>(T property, string propertyName)
    {
        if (IsolatedStorageSettings.ApplicationSettings.Contains(propertyName))
            IsolatedStorageSettings.ApplicationSettings[propertyName] = property;
        else
            IsolatedStorageSettings.ApplicationSettings.Add(propertyName, property);

        IsolatedStorageSettings.ApplicationSettings.Save();
    }

When the app runs, I can read all settings I stored in IsolatedStorageSettings.ApplicationSettings.

But when I re-open my app (open it from the app list), the IsolatedStorageSettings.ApplicationSettings-Dictionary contains Zero (0) Keys and Values.

Am I missing something?

I used the ISETool.exe to take snapshots of the IsolatedStorage of my app (thanks to chepene). I saw this behaviour: when I wrote the Settings (that means after the SaveProperty<T>() function finished), and the app is still running, I have the Settings saved in _ApplicationSettings. This agrees with my Observation that I can read from the IsolatedStorageSettings.ApplicationSettings when the app is running. The _ApplicationSettings-file also exists when the is tombstoned or not running (when I can Access it by Holding the back-button of the phone and when the app is closed with the back-button).

But when the app is opened again (via the app list), the _ApplicationSettings-file is gone...

I also see that, when I'm writing a file into the IsolatedStorage with:

SharedStorageAccessManager.CopySharedFileAsync(
    Windows.Storage.ApplicationData.Current.LocalFolder, fileName+"orig", 
    Windows.Storage.NameCollisionOption.ReplaceExisting, fileID);

and when I then don't read this file, it is gone when I open the app the next time.

By the way, to avoid confusion: I am not reinstalling the app each time I open it.

If you need more Information please ask.

Any help appreciated.

like image 784
Rico-E Avatar asked Jun 13 '13 11:06

Rico-E


1 Answers

With AppSettings, I've seen something similar on WP7/7.5, but it happened only when my property-value's type was a class that was not known to the serializer.

Are you sure that there were no exceptions:

  • during Save
  • during App Exit (since the App may dump the settings at that point)
  • during the time that App loads the settings for the first time after launch?

Note that this doesn't necessarily must mean the app crashing. I mean, any exceptions, those internally silenced or user-handled too. Please check the VisualStudio's Output panel for "first chance exceptions" log. If any I/O or security or serialization exception shows up, then investigate there. If i remember well, there's even a whole set of isolated-storage exceptions that are easily interceptable from debug/exceptions menu.

However, the issues I had with unknown or nonserializable types does not explain at all why your extra non-appsettings files would evaporate.

Another thought: maybe some additional tool performs something like 'clean deploy' for you? I don't remember exactly, but I think that VisualStudio's deployment cycle was quite plain:

  • rebuild
  • remove/uninstall old app from device -- so probably purges isolatedstorage
  • install new app onto device

So, maybe that's the cause? Hm.. on afterthought and re-reading your question again, you've said about running the app from the applist, so that rather is not the case. Be sure to check firstchance exceptions then!

like image 147
quetzalcoatl Avatar answered Sep 22 '22 18:09

quetzalcoatl