Get AppSettings Section

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I am getting the AppSettings section as follows:

AppSettingsSection appSettingSection =
(AppSettingsSection)ConfigurationManager.GetSection("appSettings");

However, I am getting the following error:

Unable to cast object of type
'System.Configuration.KeyValueInternalCollection' to type
'System.Configuration.AppSettingsSection'.

What am I doing wrong?

Thanks,

Miguel
 
Mismatching objects...

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection appSettingSection =
(AppSettingsSection)config.GetSection("appSettings");

But I am building a custom Web.Config section and I am using the
following to get my section:

object projSetings =
ConfigurationManager.GetSection("projSettings");

So I though I could use it directly only by setting the type. I am
going to try your approach ...

I am having troubles with my custom configuration section and no one
is able to answer me ... I will try something else and probably post a
new thread about it.
 
Mismatching objects...

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
AppSettingsSection appSettingSection =
(AppSettingsSection)config.GetSection("appSettings");

Ooops, I am getting the following error:

"exePath must be specified when not running inside a stand alone exe"

In: System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

Any idea?

Thanks,
Miguel
 
Yes -  my fault, I'm afraid...

System.Configuration.Configuration config =
ConfigurationManager.OpenWebConfiguration(ConfigurationUserLevel.None);

There is not OpenWebConfiguration method in
ConfigurationManager ... :-)
 
I've been trying to use this technique to get the appSettings section, but I
cannot figure out how to cast the result of GetSection(). Any ideas? I keep
coming back to the same tail chasing.

Simply put, how does one access the appSettings section using
WebConfigurationManager?
 
My bad...I was looking in the wrong namespace...was looking in
System.Web.Configuration instead of System.Configuration. Slapping my own
paw...
 
Back
Top