user.config file not being created but app.config is?

My program has some settings built in which all have a User Scope. However when the program launches it only creates the AppName.exe.config file, which contains the settings .

When saving a setting later on during runtime, it creates the user.config file (which previously didn't exist) in the AppData/Local/AppName/ location, but that file only contains the saved setting.

Why does this happen? Why won't it create the user.config or use that on startup if it exists?


From Application Settings Architecture at MSDN:

  • Application-scoped settings can be stored in either the machine.config or app.exe.config files. Machine.config is always read-only, while app.exe.config is restricted by security considerations to read-only for most applications.

  • User-scoped settings can be stored in app.exe.config files, in which case they are treated as static defaults.

  • Non-default user-scoped settings are stored in a new file, user.config, where user is the user name of the person currently executing the application. You can specify a default for a user-scoped setting with DefaultSettingValueAttribute. Because user-scoped settings often change during application execution, user.config is always read/write.

  • What you're seeing first is (what you've called) your "built in settings" being stored as (what Microsoft calls) "static default" user-scoped settings, which get stored in app.exe (as per 2).

    And then when you write back your settings at runtime, they're treated as "non-default" user-scoped settings, and they're being written to user.config (as per 3) hence why only then do you see the user.config file created.

    In short, there's no need for a per-user user.config file, as long as the user-scoped settings are the same (defaults) for everyone.

    链接地址: http://www.djcxy.com/p/11810.html

    上一篇: 如何在可移植类库中序列化一个类?

    下一篇: 没有创建user.config文件,但app.config是?