CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    43

    AppSettings returns null value

    Hi, I have come across a rather strange problem, seems quite straightforward, but I can't figure out what is wrong here:


    I have a C# program with an application configuration file (app.config added in Visual Studio 2005). The contents of app.config are:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <appSettings>
    <add key="KeyName" value="KeyValue"/>
    </appSettings >
    </configuration>


    Now when I try to read the values from my config file
    string sTemplateFile = ConfigurationManager.AppSettings.Get("KeyName");

    or

    string sTemplateFile = ConfigurationManager.AppSettings["KeyName"];

    it returns null value

    I have created the config file using the VS template. I can see the config file in my debug folder also.

    Can anyone shed some light what is going on?

    Thanks
    Last edited by sunsilk10; July 8th, 2008 at 09:58 AM.

  2. #2
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: AppSettings returns null value

    what does this return when you run it?

    Code:
    bool hasKeys = ConfigurationManager.AppSettings.HasKeys();

  3. #3
    Join Date
    Apr 2005
    Posts
    43

    Re: AppSettings returns null value

    hasKeys returns false.
    I think I might know the cause of the problem.

    I am creating a class, which will be added as a tool in another main application.

    Now, when I debug my C# program. I am launching the main application which contains my tool. I guess it is looking for the app.Config in the main application rather than in my program.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured