Why are persisted user settings not loaded?

大兔子大兔子 提交于 2019-11-28 10:11:27

If you are recompiling the application between runs, note that it will consider that a new version of the app and will not automatically load per-user settings. You need to call Settings.Default.Upgrade in this situation.

One way to do this only when needed is to add a NeedsUpgrade setting (value True) to the application's default per-user settings. On app startup, check if NeedsUpgrade is true. If so, call Upgrade, set NeedsUpgrade to False, and save the settings. The next time the app version changes, NeedsUpgrade will reset to True and you'll auto-call Upgrade to bring in any existing user settings again.

Make sure you're setting NeedsUpgrade after calling Upgrade, or it will get wiped out when the settings are upgraded.

if (Settings.Default.NeedsUpgrade)
{
    Settings.Default.Upgrade();
    Settings.Default.NeedsUpgrade = false;
    Settings.Default.Save();
}

This sounds like you're debugging the application from Visual Studio when every time you start a new session you start with the default data.

If you're seeing this with an installed release, then I would guess you're not actually using the string values when you think you are.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!