ClickOnce overwrite user settings (.net core 3.1)- Settings.Default.Upgrade() not working

Konstand Du Plessis 1 Reputation point
2021-01-26T10:33:48.867+00:00

Hi all

I have a small offline wpf app making use of user settings and click once deployment.
No matter what I do, I cannot retain the user settings after clickonce updates and resets all values to defaults.
I have tried the Settings.Default.Upgrade() recommendation, but it does not work.
Settings.Default.GetPreviousVersion("propertyname") also always returns null.

I also tested this in a small desktop app, same results. is this something missing in .net core 3.1?

I am left to either throw out the use of built in user settings or click once...

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,669 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,611 Reputation points
    2021-01-29T09:02:19.473+00:00

    Hi KonstandDuPlessis-5459,
    If a previous version of the settings file exists, it will copy its value to the latest version every time the application is launched.
    In other words,ClickOnce copy user-level settings forward to the next version's cache when the user gets an update.
    For more discussion on this problem, you can refer to this thread.
    And you can try the method that Agustin Meriles provided.
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Konstand Du Plessis 1 Reputation point
    2021-02-02T06:05:31.6+00:00

    There is nothing strange to the code, but it still overwrites the 2 with 1 after update

    MainForm.xaml.cs:

    using System.Windows;

    namespace TestSettingsApp
    {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
    public MainWindow()
    {
    InitializeComponent();
    }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Properties.Settings.Default.Setting = settingTxt.Text;
            Properties.Settings.Default.Save();
            settingLbl.Content = Properties.Settings.Default.Setting;
        }
    
        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {            
            if (Properties.Settings.Default.UpgradeSettings)
            {
                Properties.Settings.Default.Upgrade();
                Properties.Settings.Default.UpgradeSettings = false;
                Properties.Settings.Default.Save();
            }
            settingLbl.Content = Properties.Settings.Default.Setting;
        }
    }
    

    }


  3. Erick Heredia 1 Reputation point
    2022-05-13T18:37:10.593+00:00

    In case someone hasn't found a way to fix this.

    What worked for me to solve it was Sign the application in Project properties -> Singing -> "Sign the assembly"

    this even though I already sign the application when publishing in click once, then I sign the application in both places.

    201835-image.png