isolatedStorageSettings.ApplicationSettings 不会被存储以重新启动

发布于 2025-01-05 18:13:48 字数 374 浏览 0 评论 0原文

我正在编写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

汐鸠 2025-01-12 18:13:48

事实证明问题根本不在模拟器中,所以每个人都认为这是模拟器中“设计使然”的结果是错误的(但我无法撤消我的赞成票,因为它们已被锁定)。

问题是我试图保留一个不可序列化的类,而 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.

一个人练习一个人 2025-01-12 18:13:48

此行为是模拟器上“设计使然”的。

我建议您的代码按以下步骤操作。
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.

这个俗人 2025-01-12 18:13:48

检查该问题:Windows Phone 中的自动登录过程7.1 应用程序

  1. 在模拟器上,IsolatedStorage 在重新加载后不会持久,这适用于文件和应用程序设置。
  2. 您可以使用 wp7 sdk 中的独立存储资源管理器工具拍摄独立存储内容的快照并在重新启动后恢复它:点击
  3. 在隔离存储持久的真实设备上,不会出现该问题。

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.
南七夏 2025-01-12 18:13:48

我遇到了同样的错误(发生错误是因为停止调试器后密钥被删除),我发布了一个与此相关的问题: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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文