0

I am trying to change the values of certain appSettings entries in app.config. I think I've got everything right but I can't seem to write to the file. I'm thinking it's a permissions issue, and wondering exactly what user is writing to the file, when the executable attempts a write.

    public partial class Credentials : Form
{
    public Credentials()
    {
        InitializeComponent();

        byte[] userNameBytes = Convert.FromBase64String(Properties.Settings.Default.UserName);
        byte[] passwordBytes = Convert.FromBase64String(Properties.Settings.Default.Password);

        textUserName.Text = Encoding.UTF8.GetString(userNameBytes);
        textPassword.Text = Encoding.UTF8.GetString(passwordBytes);
    }

    private void btnSave_Click(object sender, EventArgs e)
    {
        byte[] userNameBytes = Encoding.UTF8.GetBytes(textUserName.Text);
        byte[] passwordBytes = Encoding.UTF8.GetBytes(textPassword.Text);

        Properties.Settings.Default.UserName = Convert.ToBase64String(userNameBytes);
        Properties.Settings.Default.Password = Convert.ToBase64String(passwordBytes);
        Properties.Settings.Default.Save();

        Close();
    }
}
Fred Chateau
  • 869
  • 1
  • 6
  • 16
  • Are you receiving any exceptions or other feedback? What happens when you 'can't seem to write to the file'? – John Arlen Jun 23 '14 at 18:46
  • Nothing, it just doesn't write to the file. – Fred Chateau Jun 23 '14 at 18:54
  • User settings are stored in user.config - located under the user's data folder. See: http://stackoverflow.com/questions/469742/where-are-user-mode-net-settings-stored – John Arlen Jun 23 '14 at 19:55
  • Did you read the linked question and answer? Have you checked the file in your user profile directory? – John Arlen Jun 24 '14 at 13:43
  • Well, the settings seem to be persisting some of the time but not all of the time. I wonder if this could have anything to do with developing an application in .NET 2.0 while running it on Windows 8.1. – Fred Chateau Jun 24 '14 at 18:15

1 Answers1

0

The problem was that I had set the assembly version to auto-increment. Every time I rebuilt the project, it had a new assembly version number.

The user settings storage contains the assembly version number in the folder path, so every time I rebuilt the project it stored the user settings in a new location. Disabling the version auto-increment allowed the settings to be retrieved each time the app was opened.

Fred Chateau
  • 869
  • 1
  • 6
  • 16