I tried to use ConfigurationManager for the first time so thats what I did:
1.) created a new Project (TestProject)
2.) rightclick on TestProject -> Add -> New Item -> Application Configuration File (Name: Conf.config)
3.) I edited the file so its looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="key1" value="output1"/>
<add key="key2" value="output2"/>
<add key="key3" value="output3"/>
</appSettings>
</configuration>
Now If I try to read the config my code is telling me that its empty :/
NameValueCollection appSettings = ConfigurationManager.AppSettings;
if (appSettings.Count == 0) //always true
Console.WriteLine("something is wrong");
Even if I try ConfigurationManager.AppSettings["key1"] I dont get any output. Hm what am I doing wrong?
If you are doing testing, then try to mock your environment, instead of accessing configuration files, database, etc.
Implement this interface like this:
But for your testing, use mocked configuration (I used Moq for example):
BTW application configuration file should have name
App.config.