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
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?
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
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
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.
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")