0

I have defined:

public static string Firstname { get; set; }
public static string Surname { get; set; }
public static bool DocBook5 { get; set; }
public static string Language { get; set; }

I stored that information in a App.config.

Then i used that to load and connect:

Firstname = ConfigurationManager.AppSettings["firstname"];
Surname = ConfigurationManager.AppSettings["surname"];
DocBook5 = Convert.ToBoolean(ConfigurationManager.AppSettings["docbook5"]);
Language = ConfigurationManager.AppSettings["language"];

But if i'm giving out the properties content with Console.WriteLine it looks like the properties are empty. The full code of the GetConfig class can be shown there

Maybe anyone knows why?

Sascha Manns
  • 2,331
  • 2
  • 14
  • 21

2 Answers2

1

As mentioned in my comments you are reading the wrong section not from appsetting . If you need a custom section in you config please follow this link .http://haacked.com/archive/2007/03/12/custom-configuration-sections-in-3-easy-steps.aspx/ else move them to appsetting section

Yashveer Singh
  • 1,914
  • 2
  • 15
  • 23
0

Look at your App.config. The data you stored is in UserSettings and not in appSettings, but you fetched the data from appSettings.

Either you put all your data in appSettings, or you define configSections, in which you add the name UserSettings. (Use 'GetSection' instead of ' AppSettings')

Later, in code, you need to request the specific section, and get the data from there.

Edit: Let me know if you want code example, to match your App.config file

Ori Nachum
  • 588
  • 3
  • 19
  • Hi Ori, can you provide a code example please? I tried it out like so: ConfigurationManager.GetSection("firstname").ToString(); but that doesn't work. – Sascha Manns Jan 16 '17 at 09:45
  • You want to get the section 'UserSettings' (Working on it) – Ori Nachum Jan 16 '17 at 10:02
  • Yes. That would be great :-) – Sascha Manns Jan 16 '17 at 10:13
  • Trying to make this work (I have this in my code, but it's not accessible current - I'm at work) Check out the question here: http://stackoverflow.com/questions/20195198/how-to-use-configurationmanager-appsettings-with-a-custom-section – Ori Nachum Jan 16 '17 at 10:28