The application loses all settings when updating the application

This is a problem that only occurs to some users. Whenever I release a new version of my application in the Marketplace, I receive emails from users saying that all the settings in the application are lost.

I cannot reproduce this myself, and I have no code that can erase an isolated file.

It would be great if anyone out there knew what might cause this.

+6
source share
2 answers

Update: Not sure if the following rules apply for WP7 applications: I will stay here just in case. I just tried this for regular applications.

You will need to β€œupdate” the old settings file.

You also need to know when you need it (i.e. only when installing a new version).

To find out when you need to update your settings, add the logical name (say) NeedSettingsUpgrade to your settings and by default it is true.

Then call the following function somewhere near the start of Main ():

/// <summary>Upgrades the application settings, if required.</summary> private static void upgradeApplicationSettingsIfNecessary() { // Application settings are stored in a subfolder named after the full #.#.#.# version number of the program. This means that when a new version of the program is installed, the old settings will not be available. // Fortunately, there a method called Upgrade() that you can call to upgrade the settings from the old to the new folder. // We control when to do this by having a boolean setting called 'NeedSettingsUpgrade' which is defaulted to true. Therefore, the first time a new version of this program is run, it will have its default value of true. // This will cause the code below to call "Upgrade()" which copies the old settings to the new. // It then sets "NeedSettingsUpgrade" to false so the upgrade won't be done the next time. if (Settings.Default.NeedSettingsUpgrade) { Settings.Default.Upgrade(); Settings.Default.NeedSettingsUpgrade = false; } } 

Note. Of course, you need to call Settings.Default.Save() before your program exits, otherwise changes to the settings will not be saved.

+3
source

My approach to this is to use the build version number as a trigger for updating. At the first start, the settings are saved in the format required for version 1.0 and version 1.0.0.0. When an update occurs, it compares the saved installation number (1.0.0.0) with the updated build number 1.1.0.0 and decides that an update is required.

I found that performing redistribution for the visual studio did not guarantee to make an update, sometimes it deleted, reinstalled, which was not so good. So I switched to using Windows Phone Powertools to check my "upgrade" path, as it reliably performs updates.

+2
source

Source: https://habr.com/ru/post/913014/


All Articles