473,387 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Get AppSettings Section

Hello,

I am getting the AppSettings section as follows:

AppSettingsSection appSettingSection =
(AppSettingsSection)ConfigurationManager.GetSectio n("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
Nov 6 '08 #1
8 8955
"shapper" <md*****@gmail.comwrote in message
news:46**********************************@a29g2000 pra.googlegroups.com...
What am I doing wrong?
Mismatching objects...

System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);
AppSettingsSection appSettingSection =
(AppSettingsSection)config.GetSection("appSettings ");
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '08 #2
On Nov 6, 1:39*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"shapper" <mdmo...@gmail.comwrote in message

news:46**********************************@a29g2000 pra.googlegroups.com...
What am I doing wrong?

Mismatching objects...

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

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
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.
Nov 6 '08 #3
On Nov 6, 1:39*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"shapper" <mdmo...@gmail.comwrote in message

news:46**********************************@a29g2000 pra.googlegroups.com...
What am I doing wrong?

Mismatching objects...

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

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
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(Configur ationUserLevel.None);

Any idea?

Thanks,
Miguel
Nov 6 '08 #4
"shapper" <md*****@gmail.comwrote in message
news:7c**********************************@p31g2000 prf.googlegroups.com...
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(Configur ationUserLevel.None);

Any idea?
Yes - my fault, I'm afraid...

System.Configuration.Configuration config =
ConfigurationManager.OpenWebConfiguration(Configur ationUserLevel.None);
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '08 #5
On Nov 6, 2:53*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.netwrote:
"shapper" <mdmo...@gmail.comwrote in message

news:7c**********************************@p31g2000 prf.googlegroups.com...
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(Configur ationUserLevel.None);
Any idea?

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

System.Configuration.Configuration config =
ConfigurationManager.OpenWebConfiguration(Configur ationUserLevel.None);

--
Mark Rae
ASP.NET MVPhttp://www.markrae.net
There is not OpenWebConfiguration method in
ConfigurationManager ... :-)
Nov 6 '08 #6
"shapper" <md*****@gmail.comwrote in message
news:d2**********************************@d36g2000 prf.googlegroups.com...
There is not OpenWebConfiguration method in ConfigurationManager ... :-)
http://msdn.microsoft.com/en-us/library/ms151456.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 6 '08 #7
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?

"Mark Rae [MVP]" wrote:
"shapper" <md*****@gmail.comwrote in message
news:d2**********************************@d36g2000 prf.googlegroups.com...
There is not OpenWebConfiguration method in ConfigurationManager ... :-)

http://msdn.microsoft.com/en-us/library/ms151456.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 19 '08 #8
My bad...I was looking in the wrong namespace...was looking in
System.Web.Configuration instead of System.Configuration. Slapping my own
paw...

"Mark Rae [MVP]" wrote:
"shapper" <md*****@gmail.comwrote in message
news:d2**********************************@d36g2000 prf.googlegroups.com...
There is not OpenWebConfiguration method in ConfigurationManager ... :-)

http://msdn.microsoft.com/en-us/library/ms151456.aspx
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Nov 19 '08 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: lobrys | last post by:
Hello everybody! Ma question est simple : Est il possible de supprimer la section appSettings en memoire pour se baser de nouveau sur le fichier de config. Resumé bref de ce que je veux...
2
by: hazz | last post by:
I have spent more time than I care to admit trying to track down a very subtle error. Here is my app's xx.exe.config file. <?xml version="1.0" encoding="utf-8" ?> <configuration>...
3
by: Celebrate | last post by:
My application works fine when I run it locally but when I transfer it to our NEW Windows 2003 Web Edition server, I get a strange error. I've isolated the problem to when I issue a...
4
by: Robert Pfeffer | last post by:
Hi, I have a rather unusual problem. I have a very simple ASP.NET application, basically hello world type. I created it with Visual Studio 2003 and am running it in debug mode. It runs fine...
2
by: Fuehner | last post by:
Everyone-- I installed the .NET 2.0 framework on a server that also has version 1.1 installed. A few of my applications override the "appSettings" section in the web.config with a custom config...
1
by: Jenny | last post by:
Hello, I read my applications App.Config file using ConfigurationSettings.AppSettings When I try to check it's last access write time using File.GetLastWriteTime and the refresh new data...
1
by: Sergei Shelukhin | last post by:
Hi. Is is possible to divide appSetting in two, having some values stored in web.config itself and some in a section referenced in appSettings file="...." attribute?
5
by: Osamede Zhang | last post by:
I just can't understand what appSettings means, how it work thanks for your read osamede
6
by: Nick | last post by:
Hi there, I have a Windows Service application that has a load of settings defined, I can access these using My.Settings. I would like to pass the NameValueCollection of the settings to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.