isolatedStorageSettings.ApplicationSettings 不会被存储以重新启动
我正在编写 WP7 (Mango) 应用程序。 我将值存储在 WP7isolatedStorageSettings.ApplicationSettings 中,然后调用 IsolatedStorageSettings.ApplicationSettings.Save();
如果我按返回并离开屏幕,然后我回来,我就可以很好地读取值。 但是,如果我在调试器中按重新启动(或者只是从模拟器重新启动),ApplicationSettings 会抛出 KeyNotFoundException,就好像它没有持续存在...
我还没有在设备上尝试过,目前还没有可用的设备。
我可能做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
事实证明问题根本不在模拟器中,所以每个人都认为这是模拟器中“设计使然”的结果是错误的(但我无法撤消我的赞成票,因为它们已被锁定)。
问题是我试图保留一个不可序列化的类,而 wp7 通过在下一个
Save()
时丢弃所有我的设置来处理这个问题。当我删除那个单个 Add() (或者更准确地说,使用 JSON.net(可以处理它)序列化该对象,并保留 json 字符串)时,所有问题都消失了。尽管如此,wp7 的行为还是很荒谬。
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.
此行为是模拟器上“设计使然”的。
我建议您的代码按以下步骤操作。
1. 检查Key是否可用
2. 如果没有,则为其设置默认值。
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.
检查该问题:Windows Phone 中的自动登录过程7.1 应用程序
Check that question: Automatic login process in Windows Phone 7.1 application
我遇到了同样的错误(发生错误是因为停止调试器后密钥被删除),我发布了一个与此相关的问题:Windows Phone 7.1 应用程序中的自动登录过程。建议您使用站点设置而不是应用程序设置。另一种选择:http://www.codeguru.com/csharp/.net/wp7/article.php/c19215/Using-Isolated-Storage-for-your-Windows-Phone-7-WP7-App.htm。希望它能解决您的问题。
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.