Cannot read in the keys from app.config (.NET 2.0)



Hey guys,

I'm stumped! :( I've been trying now for the last four days to read in
the settings from an app.config file, but i've failed miserably, at
what seemed like a simple task.

I was trying to find out how the whole System.Configuration namespace
is working. So, I made a simple C# windows application: One form, with
a single textbox and and a simple "Load" button. this is what's in the
Event handler:

private void cmdLoad_Click( object sender, EventArgs e )
// txtSettings is a textbox
txtSettings.Text =


BUT! when i click on the load button, the textbox does not get
assigned any value! i mean, nada, zilttz, String.Empy, "" . I set up a
breakpoing on the assignment above and i examined AppSettings[] . Turns
out the AllKeys member has 0 (zero) dimensions. I was flabergasted :(

Following is my App.settings file. I added this file by right clicking
on the solution explorer, on the Project name (not the solution name)
and then selecting "add new item ->
Application Configuration file.

Then, i went into Project Properties, clicked on the "Settings" tab and
added three key/value pairs: MySetting, MyOtherSetting and
MyOtherSetting. all three are at application level.

<?xml version="1.0" encoding="utf-8" ?>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGroup, System,
Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConfigurationExample.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System,
Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
<setting name="MySetting" serializeAs="String">
<setting name="MyOtherSetting" serializeAs="String">
<value>Tzimako alaka!</value>
<setting name="MyLastSetting" serializeAs="String">
<value>ALL YOUR BASE</value>
<supportedRuntime version="v2.0.50727" />

Here are some questions:

i've seen plenty of 1.1 example which ALL use appSettigns instead of
applicationSettings. Keep in mind this is a 2.0 application file. And
yes, appSettings WORKS GREAT if i add that section in manually.

1) is the <appSettings> section still required by the 2.0 framework in
order to read in application settings data?

1.1) if yes, why isn't it explicitely created or why doesn't the
preprocessor/compiler throw a warning about it?

1.2) Yes, i could use the <appSettings> section and do my job
worderfully and get this over with. But that's not the point: If 2.0
has it's own way of retrieving application settings data, i should be
able to use *THAT* instead of the depresiated 1.1 way, shouldn't I?
Where am I ****ing up?

2) requirePermission="false" <-- what does this setting do?
2.1) why does VS2k5 bitch about it not being declared?
2.2) do I need to declare it?
2.2.1) if yes, where and how?

thanks guys, looking forward to your answers.

George Marselis




Have a look in the 'Settings.Designer.cs' file generated in your app to
get a better idea of what is going on - meanwhile try

txtSettings.Text = {your

Have fun


hey Howard, thanks for the reply. Works great! but isn't this kinda of
lame? i would like to know why my set up doesn't work


hey Howard, thanks for the reply. Works great! but isn't this way,
kinda of lame? i would like to know why my set up doesn't work




I'd much rather have a named method that would fail at compile time,
that a string indexer that might fail at runtime!!

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question