2

I'm trying to share my application-settings between different assemblies as readonly object (e.g. a Dictionary).

The Settings are the default ones used by WPF-applications. I want to enable the user to changed some settings before starting the action inside the WPF-application. I only need the current settings-values as readonly to send them to the other assemblies.

Currently I have this in my MainWindows OnLoaded-callback.

var t = Settings.Default.PropertyValues.Cast<SettingsPropertyValue>().ToDictionary(value => value.Name, value => value.PropertyValue);

t is the Dicitionary I want to share/pass to the other assemblies that work on them (but do not change them).

However, Settings.Default.PropertyValues is empty and so is t.

My MainWindow already has some user-interface(s) to set some of those values like:

Settings.Default.ProjectRootDirectory = newFolder;
Settings.Default.Save();

var t = Settings.Default.PropertyValues.Cast<SettingsPropertyValue>().ToDictionary(value => value.Name, value => value.PropertyValue);

Settings.Default.Reload();

After setting Settings.Default.ProjectRootDirectory = newFolder, Settings.Default.PropertyValues has all properties loaded correctly.

How can I have the current setting-values without setting one before?

Noam M
  • 3,107
  • 5
  • 26
  • 41
KingKerosin
  • 3,379
  • 4
  • 33
  • 70
  • You have in your app.config the settings saved? The settings get their default values if they neither could be loaded from App.config or user.config if it is a user configurable setting. How are you defining your settings? – Alois Kraus Apr 17 '16 at 11:56
  • I define them via project-settings interface. It then get stored as `Settings.settings` in the projects `Properties` folder as xml and a `internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase` .cs-file – KingKerosin Apr 17 '16 at 12:00
  • A dictionary is not editable in the settings gui. So I guess you do not have any dictionary settings inside it. – Alois Kraus Apr 17 '16 at 12:50
  • It's not about how I set the properties. It's about how to read them into a Dictionary, as they are empty as long as I don't set a value explicitly. See http://stackoverflow.com/questions/89149/c-why-does-settings-propertyvalues-have-0-items – KingKerosin Apr 17 '16 at 12:58

0 Answers0