configuration variable access

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saboorahmed
    New Member
    • Apr 2010
    • 1

    configuration variable access

    hi
    i want to access value of a variable in app.config

    my config file looks like
    Code:
    <configuration>
      <applicationSettings>
        <wpf1.Properties.Settings>
          <setting name="ThreadDelay" serializeAs="String ">
            <value>5000</value>
          </setting>
        </wpf1.Properties.Settings>
      </applicationSettings>
    </configuration>
    and in code behind

    Code:
    string delay = System.Configuration.ConfigurationSettings.AppSettings["ThreadDelay"].ToString();

    but it comes with an error that object reference not set to an instance of object

    my .config filename was wpf1.config as i rename it to app.config it start working fine
    any suggesstions
    Last edited by tlhintoq; Apr 12 '10, 02:17 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    TIP: When you first created your question you were asked to wrap your code with [code] tags.
    [imgnothumb]http://files.me.com/tlhintoq/10jihf[/imgnothumb]
    It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      Originally posted by OriginalPoster
      "How do I fix a 'object reference not set to an instance of an object' error?
      The line your code stopped on while debugging holds all your answers.
      One of the variables/objects was created but not initialized. For example:
      Code:
      string TempString;// Created but not initialized so this is still null
      //versus
      string TempString = string.empty;
      Debug your project again. This time, when it breaks on a line look at the Locals pallet to see which variable/object is null. You can also hover your mouse over each variable and the hothelp will shows its value. One of them will be null.

      my .config filename was wpf1.config as i rename it to app.config it start working fine
      any suggesstions
      Since renaming the file has solved the problem... what do you need suggestions for?

      Comment

      • stoogots2
        New Member
        • Sep 2007
        • 77

        #4
        What it sounds like to me is that you need your config file to be named as your executablename. exe.config. That is how my config files are named after compilation. Just a thought.

        Comment

        Working...