I am trying to read StartingMonthColumn and CategoryHeadingColumn from the below app.config file using the code
ConfigurationSettings.AppSettings[\"StartingM
The reason is simple, your call to ConfigurationSettings.AppSettings
is not returning the required config file. Please try any of the following ways:
ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location).AppSettings["StartingMonthColumn"]
Hope this helps
Just for the future reference, you just need to add System.Configuration
to your references library:
ConfigurationSettings.AppSettings is obsolete, you should use ConfigurationManager.AppSettings instead (you will need to add a reference to System.Configuration)
int value = Int32.Parse(ConfigurationManager.AppSettings["StartingMonthColumn"]);
If you still have problems reading in your app settings then check that your app.config
file is named correctly. Specifically, it should be named according to the executing assembly i.e. MyApp.exe.config
, and should reside in the same directory as MyApp.exe
.
Try:
string value = ConfigurationManager.AppSettings[key];
For more details check: Reading Keys from App.Config
Also add the key "StartingMonthColumn" in App.config that you run application from, for example in the App.config of the test project.
Try to rebuild your project - It copies the content of App.config
to
"<YourProjectName.exe>.config" in the build library.