简体   繁体   English

设置升级没有任何作用

[英]Settings Upgrade Does Nothing

I have a C# application that uses several user settings to store its data.我有一个 C# 应用程序,它使用多个用户设置来存储其数据。 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.问题是:对 Upgrade() 的调用什么也不做。 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. PS:我检查了一组旧的设置是否以合理的值存储在磁盘上。 So there should be definately something to work with for Upgrade().所以肯定有一些东西可以用于 Upgrade()。

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.为了解决这个问题,我使用 .snk 文件签署了我的程序集。 This way the hash now stays fixed, and the upgrade works.这样散列现在保持固定,并且升级有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM