Per the documentation, inspection of the generated code and the question, "Why are my application settings not getting persisted?", application-scoped settings are read-only.
To update application-scoped settings, you'll need to change the appropriate <appsettings>
value in your app.config
file:
Note that a change to an app.config
file is supposed to restart the app domain, so trying to update your own app.config
may behave a little differently than what you might expect.
Also note that the changes will be made to the generated *.exe.config
file in your bin
directory, not to the app.config
file in your Visual Studio solution.
Another thing to consider: in a deployed application, unless you run with "elevated privileges", you're also unlikely to have write access to the app.config
file.
If you want to persist/update this sort of app settings, take a page from the OS X book and create a *.plist
:
On application start, check for an XML file for your settings in a known location to which that app has read/write access. In OS X, the app-level settings live in /Library/Preferences
; user level preferences live in ~/Library/Preferences
.
If it doesn't exist, create it, populating it with the default values for the settings in question (which could be as simple as copying your <appsettings>
element from app.config
.
Read your app-level settings from that file.
Place a FileSystemWatcher
on that file to hook any changes and update the settings.
There you go. Now, you can update your app-level settings to your heart's content. If you ever need to revert, all you have to do is blow away the *.plist
file.