System.Configuration.ConfigurationManager.AppSettings Does Not Exist

I am trying to upgrade a VB 2003 program to VB 2005.

One warning I am getting is:

'Public Shared ReadOnly Property AppSettings() As System.Collections.Specialized.NameValueCollection' is obsolete: 'This method is obsolete, it has been replaced by System.Configuration!System.Configuration.ConfigurationManager.AppSettings' C:\CS\CSolution\bin\Classes\Utilities.vb 8380 25 CSolution

1) what does the ! mean in the terminology of "System.Configuration!" above?

2) More importantly, in "System.Configuration.ConfigurationManager.AppSettings"I cannot get ConfigurationManager to show up as an option in intelesense. It shows as an error if I try to use it anyway.

3) I have searched help, and for the life of me, I cannot figure out how to read a simple app.config file value.

Please advise.

Thanks!

bob

[1197 byte] By [BobInIndy] at [2007-12-31]
# 1

BobInIndy wrote:

1) what does the ! mean in the terminology of "System.Configuration!" above?

It's shorthand for specifying the DLL and the fully qualified class/property. The form is 'assemblyname!property/class/field'. So this indicates the System.Configuration dll.

BobInIndy wrote:

2) More importantly, in "System.Configuration.ConfigurationManager.AppSettings" I cannot get ConfigurationManager to show up as an option in intelesense. It shows as an error if I try to use it anyway.

Can you post a code snippet detailing this problem?

BobInIndy wrote:

3) I have searched help, and for the life of me, I cannot figure out how to read a simple app.config file value.

Reading app.config is a pretty big subject. Can you be more specific on what type of data you want to read out of app.config?

JaredParsonsMSFT at 2007-10-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 2

Add a reference to System.Configuration.dll, and you should be able to use the System.Configuration.ConfigurationManager.

Depending on what you want kind of settings you want for your application, I would recommend that you check out the new Settings designer in Visual Studio 2005. For more info, check out http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvs05/html/vbmysettings.asp

Best regards,
Johan Stenberg

MSJohanStenberg at 2007-10-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 3

Not sure if you're still searching, but I found this

<<You can reference this directly from code using:

[C#]
string connStr = ConfigurationManager.ConnectionStrings["MainConnStr"].ConnectionString;

[VB]
Dim connStr As String = ConfigurationManager.ConnectionStrings("MainConnStr").ConnectionString

Note that the namespace for this is System.Configuration so for a console application the full namespace is required.>>

on this:

http://weblogs.asp.net/owscott/archive/2005/08/26/Using-connection-strings-from-web.config-in-ASP.NET-v2.0.aspx

Daranee at 2007-10-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 4
Have to agree with Bob. I was using

system.Configuration.ConfigurationSettings.AppSettings("Version") and it now flags it as Obsolete (even though it worked fine in Debug within the Immediate window).

I tried strTemp = system.Configuration.ConfigurationManager.AppSettings("Version")

but it flags it as 'ConfigurationManager' is not a member of 'Configuration'

I have included an Imports System.Configuration statement at the front as well. This really is poor. It shouldn't be so difficult to replace the one statement (that worked) with this new one that doesn't. C'mon Microsoft get your act together. Do you think we've all day to mess with these stupid error messages and their lack of correct guidance?

rosecalf@hotmail.co.uk

vigorniensis at 2007-10-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 5

Please note that there is a big difference between importing a namespace (putting an Imports <whatever namespace> in your file) and adding a reference to an assembly - the Import simply lets you refer to types without having to specify the fully namespace qualified type name *if you have a reference to the assembly where the type is defined*.

Adding a reference actually makes the type available to the referencing assembly (in your case, the application)

There is not a one-to-one mapping between namespace and assembly, so you can't determine which assembly a type is defined in by looking at the namespace.

Best regards,
Johan Stenberg

MSJohanStenberg at 2007-10-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 6

I have tried adding a project reference to System.configuration.dll and using the fully qualified class name:

System.Configuration.ConfigurationManager.AppSettings.Item("ReportServer")

but I get the same compile error, indicating that ConfigurationManager is not a member of Configuration. What is even more perplexing is that I have the exact same line of code in another website and it works just fine. I have even tried removing and adding the project reference again, to no avail.

Thoughts, anyone?

Jim S.

nonyabiz at 2007-10-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 7
You need to right click your References and add a reference to System.Configuration before you are able to use ConfigurationManager. For some reason, some System.Configuration options are available without this, but not all.
waden34 at 2007-10-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...
# 8

The normal procedure, adding a reference to the assembly and using the fully qualified name, worked after a reboot. I am not sure why it needed one, but it did.

The reason why System.Configuration seems to work sometimes and not others is because there are the old System.Configuration namespace and the new System.Configuration assembly have the same name. Just reference the .dll and refer to it in the manner noted throughout this thread:

System.Configuration.ConfigurationManager.AppSettings.Item("ItemName")

nonyabiz at 2007-10-9 > top of Msdn Tech,Visual Basic,Visual Basic Language...