PC Review


Reply
Thread Tools Rate Thread

ConfigurationSettings.AppSettings["foo"]

 
 
Mark
Guest
Posts: n/a
 
      11th Jan 2007
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 = ConfigurationSettings.AppSettings["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


 
Reply With Quote
 
 
 
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      11th Jan 2007
Hi,



"Mark" <(E-Mail Removed)> wrote in message
news:e6$(E-Mail Removed)...
| 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 = ConfigurationSettings.AppSettings["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 FileSystemWatcher) to detect change, if it does it
reload the entire app



--
Ignacio Machin
machin AT laceupsolutions com


 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      11th Jan 2007

It loads the first time ConfigurationSettings.AppSettings 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
ConfigurationSettings.AppSettings 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.com> wrote:

>| string blah = ConfigurationSettings.AppSettings["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 FileSystemWatcher) to detect change, if it does it
>reload the entire app


 
Reply With Quote
 
=?Utf-8?B?WE9S?=
Guest
Posts: n/a
 
      12th Jan 2007
if ur accessing web.config, use WebConfigurationManager - its faster than the
basic ConfigurationManager.
 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      12th Jan 2007

WebConfigurationManager is new to .NET 2.0 and the original post asked
about ConfigurationSettings.AppSettings 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
<(E-Mail Removed)> wrote:

>if ur accessing web.config, use WebConfigurationManager - its faster than the
>basic ConfigurationManager.


 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      12th Jan 2007
Hi,

"Samuel R. Neff" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
|
| It loads the first time ConfigurationSettings.AppSettings 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
| ConfigurationSettings.AppSettings 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


 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      16th Jan 2007

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.com> wrote:

>Hi,
>
>"Samuel R. Neff" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>|
>| It loads the first time ConfigurationSettings.AppSettings 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
>| ConfigurationSettings.AppSettings 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.


 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      16th Jan 2007
Hi,

"Samuel R. Neff" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
|
| 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


 
Reply With Quote
 
Samuel R. Neff
Guest
Posts: n/a
 
      16th Jan 2007

Use Reflector and look at ConfigurationSettings.GetConfig. 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.com> wrote:

>Hi,
>
>"Samuel R. Neff" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed)...
>|
>| 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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ConfigurationSettings.AppSettings[" ConfigurationSettings.AppSettings"] Ken Microsoft C# .NET 1 14th May 2007 09:47 PM
ConfigurationSettings.AppSettings["value"] returns a string that starts with '@' lauralucas@gmail.com Microsoft ASP .NET 2 24th Jul 2006 04:13 PM
System.Configuration.ConfigurationSettings.AppSettings.Get("...") RSH Microsoft VB .NET 2 3rd May 2006 06:58 PM
ConfigurationSettings.AppSettings["mySetting"] returning null Derrick Microsoft C# .NET 5 1st Feb 2005 08:01 PM
ConfigurationSettings.AppSettings.Get("value") Grantsss Microsoft C# .NET 1 8th Jul 2003 11:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:40 AM.