Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

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.

Check that question: Automatic login process in Windows Phone 7.1 application

  1. On emulator IsolatedStorage is not persistent after reload and that's for both files and application settings.
  2. You can use Isolated Storage Explorer Tool from wp7 sdk to take a snapshot of isolated storage content and restore it after the restart: Click
  3. That problem doesn't occur on real device where Isolated Storage is persistent.

I got the same error(The error occurs because after you stop the debugger the key get deleted), and I posted a question regards this: Automatic login process in Windows Phone 7.1 application. suggest you to use site settings instead of application settings. One more option:http://www.codeguru.com/csharp/.net/wp7/article.php/c19215/Using-Isolated-Storage-for-your-Windows-Phone-7-WP7-App.htm. Hope it solves your problem.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top