-1

C# - ConfigurationManager.AppSettings count is 0. And ideas? Here is the code:

  var appSettings = ConfigurationManager.AppSettings;

                    if (appSettings.Count == 0)
                    {
                        Console.WriteLine("AppSettings is empty.");
                    }

Running in debug. VS copies the app.config to the debug directory and names it CBCuedERI.exe.config. Here is part of the config file

<applicationSettings>
    <CBCuedERI.Properties.Settings>
        <setting name="test" serializeAs="String">
            <value>one</value>
        </setting>
    </CBCuedERI.Properties.Settings>
</applicationSettings>

I also tried this and it returns NULL

  string sss = ConfigurationManager.AppSettings.Get ( "test") ;
Mark Worsnop
  • 4,407
  • 15
  • 54
  • 79

2 Answers2

0

Your config file is incorrect, you are using the key applicationSettings instead of the correct appSettings.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
-1

ConfigurationManager.AppSettings is used for the key value pairs in appSettings section

Reading settings from app.config or web.config in .net

Community
  • 1
  • 1
Stefan
  • 446
  • 3
  • 9
  • I tried this after reading the link and returned NULL. string sss = ConfigurationManager.AppSettings.Get ( "test") ; – Mark Worsnop May 18 '17 at 00:52