ConfigurationSettings.GetConfig() always returns null

This is a discussion on ConfigurationSettings.GetConfig() always returns null within the C# Programming forums, part of the General Programming Boards category; The following always indicates that the config section is not found Code: if ((IDictionary)ConfigurationSettings.GetConfig("LogSettings") == null) { Console.WriteLine("I'm null"); return; ...

  1. #1
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696

    ConfigurationSettings.GetConfig() always returns null

    The following always indicates that the config section is not found
    Code:
    if ((IDictionary)ConfigurationSettings.GetConfig("LogSettings") == null)
    {
        Console.WriteLine("I'm null");
        return;
    }
    else
    {
    
    }
    Here's the whole content of app.config
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="LogSettings"
                 type="System.Configuration.SingleTagSectionHandler"/>
      </configSections>
    
      <LogSettings EnableLog="True"
                   LogDirPath="Log"
                   LogFileBaseName="Log"
                   ErrorEventLogFileBaseName="Log.Error" 
                   PrefixMessageWithDateTime="True"
                   ExpiryDays="15"
                   DeleteExpiredLogFiles="True" 
                   WriteErrorEventToSeparateFile="True"
                   AppendLogFileNameWithDateTime="True"
                   SendEmailOnErrorEvent="True"
                   EmailTo="a@mail.com"
                   EmailFrom="b@mail.com"
                   EmailCc="c@mail.com"
                   EmailBcc="d@mail.com" />
      
    </configuration>
    So, why haven't I been able to read "LogSettings" section? Thanks for the help.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    I tried it on another computer thinking it was bad installation, but, nope, same thing. At home was VS 2005, .NET 1.1 and 2.0; at work was VS 2003, .NET 1.1.

    Can anyone try it on their computer if the method (ConfigurationSettings.GetConfig) works at all? Thanks. I appreciate it.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    2
    Quote Originally Posted by alphaoide
    I tried it on another computer thinking it was bad installation, but, nope, same thing. At home was VS 2005, .NET 1.1 and 2.0; at work was VS 2003, .NET 1.1.

    Can anyone try it on their computer if the method (ConfigurationSettings.GetConfig) works at all? Thanks. I appreciate it.
    just an ide but have try:

    Code:
    Code:
    
    if (ConfigurationSettings.GetConfig("LogSettings" == null) //<-- with no cast?
    {
        Console.WriteLine("I'm null");
        return;
    }
    else
    {
    
    }
    (((also empty blocks should be documented)))

  4. #4
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    @notsure, same thing, the method returns null.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  5. #5
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    For two days I thought I would hate .NET. I figured out my mistake.

    I have a solution with two projects: a class library and it's driver. The App.config was in class library project, when it's supposed to go in the driver project.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked List Not Saving Value as Int
    By bar338 in forum C Programming
    Replies: 4
    Last Post: 05-04-2009, 08:53 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Help with yacc/compiler design/seg fault
    By trippeer in forum C Programming
    Replies: 1
    Last Post: 04-08-2005, 04:43 AM
  4. Problem with a menu.
    By Rare177 in forum Windows Programming
    Replies: 4
    Last Post: 09-08-2004, 12:51 AM
  5. button 'message'
    By psychopath in forum Windows Programming
    Replies: 12
    Last Post: 04-18-2004, 10:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21