Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IsolatedStorageSettings.ApplicationSettings doesn't get stored to restart

I'm writing a WP7 (Mango) application. I store values in WP7 IsolatedStorageSettings.ApplicationSettings, then I call IsolatedStorageSettings.ApplicationSettings.Save();

If I press back, and leave the screen, and I come back I can read values just fine. However if I press restart in the debugger (or just restart from the emulator) the ApplicationSettings throws a KeyNotFoundException, as if it didn't persist...
I haven't yet tried it on device, I don't have one available right now.

What can I possibly be doing wrong?

like image 794
TDaver Avatar asked Jan 17 '23 11:01

TDaver


2 Answers

It turns out the problem wasn't in the emulator AT ALL, so everyone suggesting this is "by design" in emulator turned out to be wrong (but I can't undo my upvotes as they are locked).

The problem was that I tried to persisting a non-serializable class, and wp7 handled this by throwing away ALL my settings at next Save(). When I removed that single Add() (or more precisely serialzied that object with JSON.net (which COULD handle it), and persisted the json string) all my problems simply went away.

Still, ridiculous behavior on wp7's part.

like image 111
TDaver Avatar answered May 03 '23 17:05

TDaver


This behavior is "by design" on emulator.

I suggest, below steps for your code. 1. Check Key is available or not 2. If not, then set default value to it.

like image 20
Nilay Shah Avatar answered May 03 '23 18:05

Nilay Shah