Configuration Manager

  • 12 years ago

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Configuration;

    namespace ConsoleApplication111
    {
        class Program
        {
            static void Main(string[] args)
            {

                String s = ConfigurationManager.AppSettings["Test"];
                Int32 foo = Int32.Parse(s);
                Console.WriteLine(foo);
               
            }
        }
    }
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <configSections>
    </configSections>
        <appSettings>
            <add key="Test" value="12"/>
        </appSettings>
    </configuration>

     with this code I get a
    Unhandled Exception: System.ArgumentNullException: Value cannot be null, Error. The name of the file is appconfig and it is in the same directory as the executable...

  • 12 years ago

    Hi,

    The code given in ur scenario is working fine. I copied the same code from ur posting and tested.

    Try it ...at ur end.

    Thanks

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald Knuth