An error occurred when trying to save user setting in VS to app.config

Peter Toye 191 Reputation points
2022-05-19T11:04:06.057+00:00

I've written a simple Hello Word program to test the use of settings. I set up a simple setting and tried to save it but got an error message (see screenshot). I've looked at the app.config file and the relevant section says

 <userSettings>  
    <Hello2.My.MySettings>  
        <setting name="Test" serializeAs="String">  
            <value />  
        </setting>  
    </Hello2.My.MySettings>  
</userSettings>  

This seems to have two problems:

  1. The setting name is wrong (should be 'TextSet')
  2. There's no value (probably as a result of the error).

I'm using VS 2019 version 16.11.15 on Windows 10 Home. The project was built using the Windows Forms App template.

I'm obviously doing something fairly elementary wrong here, but can't work out what. Surely something as simple of this should just work out of the box.

203694-appconfig-bug.png

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,629 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anna Xiu-MSFT 25,801 Reputation points Microsoft Vendor
    2022-05-20T06:57:36.167+00:00

    Hi @Peter Toye ,

    Welcome to Microsoft Q&A!

    It looks like that the setting shown in the App.config file doesn’t match the setting in Settings.settings. If you manually edit the setting name in App.config, was a new value added automatically in Settings.settings file?

    If it doesn’t work, please close all Visual Studio instances and repair your VS through Visual Studio Installer > More > Repair.

    Then, create a new Windows Forms App and add a setting in Settings.settings file.
    Clicking on Save and check if you can see the setting in App.config file.

    If you still have the problem, it may be a known issue: An error occurred while saving values to the app.config file.
    You can add your comment there.

    Sincerely,
    Anna
    *
    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful