-1

I have a C# application that uses several user settings to store its data. When I increase the version number of my application, those settings are lost and reset to their default values.

That's why I implemented the following code

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

as suggested here.

The problem is: the call to Upgrade() does nothing. It does not throw an exception, but it does not load any of the old settings either. Every setting still has its default value afterwards. Also my new application version stores its settings in a new folder, right next to the old settings' folder.

Am I holding it wrong? ;-)

PS: I checked that an old set of settings is stored on the disk with reasonable values. So there should be definately something to work with for Upgrade().

Boris
  • 8,551
  • 25
  • 67
  • 120
  • Are you sure UpgradeRequired is true? Have you tried checking whether [previous values are available](https://learn.microsoft.com/en-us/dotnet/api/system.configuration.iapplicationsettingsprovider.getpreviousversion?view=netframework-4.7.2)? – ikkentim Sep 04 '18 at 07:19

1 Answers1

0

Seems I found the solution. Since my assembly was not strong named/signed, a new hash was generated every time I updated my application. Thus old settings were not found and the upgrade did not work.

To fix this I signed my assembly using a .snk file. This way the hash now stays fixed, and the upgrade works.

Boris
  • 8,551
  • 25
  • 67
  • 120