Question

First strangeness:

I really wonder why do I get the different values from Settings.settings file in the debug and non-debug modes. In other words I start my application in the without debugging (run-> start without debuging) and in the debug modes (rub-> debug). And it always gives me the different values for the same key in these modes.

Second strangeness:

When I change the values stored in Settings.settings file with my application at runtime, the values aren't changed. I see the previous values in this file as I open it in Visual Studio. Note I don't forget to call Default.Save() to save the changes.

What is the reason for them? Why do they occur and how do I solve them?

Was it helpful?

Solution

The reason is simple. When you debug you do not start the application itself but a Visual Studio hosting process where your code is executed. Since settings are per executable specific you get for the VS Debugger hosted executable different previously saved settings back as if you start your application directly.

You can disable this strange behviour by selecting in your

Project Properties - Debug -

    uncheck Enable Visual Studio Hosting Process.

The settings are immutable (read only) if they are application scoped. When you call save on settings with user scope they will be stored in your user profile. The app.config contents are never changed which makes sense to allow admin only installation of an application. Later the users can change the settings by writing the "diff" to their local user profile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top