ConfigurationSettings.AppSettings["foo"]

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark

    ConfigurationSettings.AppSettings["foo"]

    Could someone provide me with details or a link on how the line of code
    executes underneath the hood? Assume it's executed in an ASP.NET
    application.

    string blah = ConfigurationSe ttings.AppSetti ngs["foo"]

    Once your application has called for the "foo" key once, how expensive is to
    call the same line again? My gut tells me that the CLR likely stores these
    values in memory in a string dictionary or similar. Looking up the value
    requires the potentially sorted collection to "lookup" the key again and
    retrieve the value hopefully leveraging a b-tree or similar in the sorted
    collection.

    Perhaps it works a different way? Just curious. Thanks.

    Mark


  • Ignacio Machin \( .NET/ C# MVP \)

    #2
    Re: ConfigurationSe ttings.AppSetti ngs["foo&qu ot;]

    Hi,



    "Mark" <markfield88@no spam.nospamwrot e in message
    news:e6$UJdbNHH A.2140@TK2MSFTN GP03.phx.gbl...
    | Could someone provide me with details or a link on how the line of code
    | executes underneath the hood? Assume it's executed in an ASP.NET
    | application.
    |
    | string blah = ConfigurationSe ttings.AppSetti ngs["foo"]
    |
    | Once your application has called for the "foo" key once, how expensive is
    to
    | call the same line again?

    Not much, only a lookup in some struct in memory ( hashtable, etc). At some
    moment the file needs to be loaded. IMO (but I have no fact to prove it) it
    happens when the application loads.

    Also remember that even as the file remains closed the engine keeps an eye
    on it (probably using a FileSystemWatch er) to detect change, if it does it
    reload the entire app



    --
    Ignacio Machin
    machin AT laceupsolutions com


    Comment

    • Samuel R. Neff

      #3
      Re: ConfigurationSe ttings.AppSetti ngs[&quot;foo&qu ot;]


      It loads the first time ConfigurationSe ttings.AppSetti ngs is called,
      not necessarily on application load.

      Hard to test in an ASP.NET app but in a winform/console app it's easy
      to verify because you can change the app.config file before calling
      ConfigurationSe ttings.AppSetti ngs and your changes are reflect (not
      usually a good idea but we did this in one situation where we wanted a
      console app to share a config file with another app sothe console app
      copied the file on startup).

      Sam


      ------------------------------------------------------------
      We're hiring! B-Line Medical is seeking Mid/Sr. .NET
      Developers for exciting positions in medical product
      development in MD/DC. Work with a variety of technologies
      in a relaxed team environment. See ads on Dice.com.


      On Thu, 11 Jan 2007 15:16:47 -0500, "Ignacio Machin \( .NET/ C# MVP
      \)" <machin TA laceupsolutions .comwrote:
      >| string blah = ConfigurationSe ttings.AppSetti ngs["foo"]
      >|
      >Not much, only a lookup in some struct in memory ( hashtable, etc). At some
      >moment the file needs to be loaded. IMO (but I have no fact to prove it) it
      >happens when the application loads.
      >
      >Also remember that even as the file remains closed the engine keeps an eye
      >on it (probably using a FileSystemWatch er) to detect change, if it does it
      >reload the entire app

      Comment

      • =?Utf-8?B?WE9S?=

        #4
        Re: ConfigurationSe ttings.AppSetti ngs[&quot;foo&qu ot;]

        if ur accessing web.config, use WebConfiguratio nManager - its faster than the
        basic ConfigurationMa nager.

        Comment

        • Samuel R. Neff

          #5
          Re: ConfigurationSe ttings.AppSetti ngs[&quot;foo&qu ot;]


          WebConfiguratio nManager is new to .NET 2.0 and the original post asked
          about ConfigurationSe ttings.AppSetti ngs which is obsolete in .NET 2.0,
          implying he's using .NET 1.1.

          Sam

          ------------------------------------------------------------
          We're hiring! B-Line Medical is seeking Mid/Sr. .NET
          Developers for exciting positions in medical product
          development in MD/DC. Work with a variety of technologies
          in a relaxed team environment. See ads on Dice.com.


          On Thu, 11 Jan 2007 17:31:00 -0800, XOR
          <XOR@discussion s.microsoft.com wrote:
          >if ur accessing web.config, use WebConfiguratio nManager - its faster than the
          >basic ConfigurationMa nager.

          Comment

          • Ignacio Machin \( .NET/ C# MVP \)

            #6
            Re: ConfigurationSe ttings.AppSetti ngs[&quot;foo&qu ot;]

            Hi,

            "Samuel R. Neff" <samuelneff@nom ail.comwrote in message
            news:hbcdq25a2m f50c79e1ja0qp4s mlremn520@4ax.c om...
            |
            | It loads the first time ConfigurationSe ttings.AppSetti ngs is called,
            | not necessarily on application load.
            |
            | Hard to test in an ASP.NET app but in a winform/console app it's easy
            | to verify because you can change the app.config file before calling
            | ConfigurationSe ttings.AppSetti ngs and your changes are reflect (not
            | usually a good idea but we did this in one situation where we wanted a
            | console app to share a config file with another app sothe console app
            | copied the file on startup).

            I think that the treatmean is different between web and win apps, in win app
            as you mentioned before you can change the config while the app is running
            and before the app access it without any consequence. If you do so in a web
            app the application will restart.


            --
            Ignacio Machin
            machin AT laceupsolutions com


            Comment

            • Samuel R. Neff

              #7
              Re: ConfigurationSe ttings.AppSetti ngs[&quot;foo&qu ot;]


              The treament related to changing the file is different, but the O.P.'s
              question was about when the data is loaded and how it's cached which
              is the same--on first access.

              Sam


              ------------------------------------------------------------
              We're hiring! B-Line Medical is seeking Mid/Sr. .NET
              Developers for exciting positions in medical product
              development in MD/DC. Work with a variety of technologies
              in a relaxed team environment. See ads on Dice.com.



              On Fri, 12 Jan 2007 09:58:43 -0500, "Ignacio Machin \( .NET/ C# MVP
              \)" <machin TA laceupsolutions .comwrote:
              >Hi,
              >
              >"Samuel R. Neff" <samuelneff@nom ail.comwrote in message
              >news:hbcdq25a2 mf50c79e1ja0qp4 smlremn520@4ax. com...
              >|
              >| It loads the first time ConfigurationSe ttings.AppSetti ngs is called,
              >| not necessarily on application load.
              >|
              >| Hard to test in an ASP.NET app but in a winform/console app it's easy
              >| to verify because you can change the app.config file before calling
              >| ConfigurationSe ttings.AppSetti ngs and your changes are reflect (not
              >| usually a good idea but we did this in one situation where we wanted a
              >| console app to share a config file with another app sothe console app
              >| copied the file on startup).
              >
              >I think that the treatmean is different between web and win apps, in win app
              >as you mentioned before you can change the config while the app is running
              >and before the app access it without any consequence. If you do so in a web
              >app the application will restart.

              Comment

              • Ignacio Machin \( .NET/ C# MVP \)

                #8
                Re: ConfigurationSe ttings.AppSetti ngs[&quot;foo&qu ot;]

                Hi,

                "Samuel R. Neff" <samuelneff@nom ail.comwrote in message
                news:dktpq2toih 7anon7bpf9flqc6 6u7a48gai@4ax.c om...
                |
                | The treament related to changing the file is different, but the O.P.'s
                | question was about when the data is loaded and how it's cached which
                | is the same--on first access.

                Do you have a link where this is described?

                Honestly I would find dificult to understand why it's loaded at first use,
                and being "watched" from the beginning. Unless of course that the first
                thing that happen when an app is loaded depends of the config, then it will
                load (at the start of the app). In this escenario the file is loaded at
                first use which coincide with the load of the app. IMHO I think this is the
                way it happens



                --
                Ignacio Machin
                machin AT laceupsolutions com


                Comment

                • Samuel R. Neff

                  #9
                  Re: ConfigurationSe ttings.AppSetti ngs[&quot;foo&qu ot;]


                  Use Reflector and look at ConfigurationSe ttings.GetConfi g. It's
                  initialized on first use.

                  Sam

                  ------------------------------------------------------------
                  We're hiring! B-Line Medical is seeking Mid/Sr. .NET
                  Developers for exciting positions in medical product
                  development in MD/DC. Work with a variety of technologies
                  in a relaxed team environment. See ads on Dice.com.


                  On Tue, 16 Jan 2007 13:50:07 -0500, "Ignacio Machin \( .NET/ C# MVP
                  \)" <machin TA laceupsolutions .comwrote:
                  >Hi,
                  >
                  >"Samuel R. Neff" <samuelneff@nom ail.comwrote in message
                  >news:dktpq2toi h7anon7bpf9flqc 66u7a48gai@4ax. com...
                  >|
                  >| The treament related to changing the file is different, but the O.P.'s
                  >| question was about when the data is loaded and how it's cached which
                  >| is the same--on first access.
                  >
                  >Do you have a link where this is described?
                  >
                  >Honestly I would find dificult to understand why it's loaded at first use,
                  >and being "watched" from the beginning. Unless of course that the first
                  >thing that happen when an app is loaded depends of the config, then it will
                  >load (at the start of the app). In this escenario the file is loaded at
                  >first use which coincide with the load of the app. IMHO I think this is the
                  >way it happens

                  Comment

                  Working...