Get AppSettings Section

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
 
S

shapper

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.
 
S

shapper

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
 
S

shapper

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

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

There is not OpenWebConfiguration method in
ConfigurationManager ... :)
 
J

Jimbo M

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?
 
J

Jimbo M

My bad...I was looking in the wrong namespace...was looking in
System.Web.Configuration instead of System.Configuration. Slapping my own
paw...
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top