|
-
May 1st, 2008, 10:51 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005]Problem with my COnfiguration Settings
Elow guys need help on why it occurs error in my vb.net2005 while on 2003 it does not have an error..Here is my code:
Code:
Dim aConfig As Configuration.ConfigurationSettings
Dim strServerName As String = aConfig.AppSettings("ServerName")
on my app.config file here is the code:
Code:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="ServerName" value="(local)"/>
</appSettings>
</configuration>
At my first child form it display no problem but when i call child of my first child form it displays "Access of shared members, constant member, enum member, or nested type through an instance; qualifying expression will not be evaluated". Why this error comes out guys? Need help on how to do it..Thanks in advance and have a nice day! God Bless..
Last edited by shyguyjeff; May 4th, 2008 at 10:15 PM.
-
May 2nd, 2008, 12:56 AM
#2
Re: [2005]Problem with my COnfiguration Settings
Firstly, that's a warning, not an error.
Secondly, looking at your code you should be able to see that you never actually create an instance of the ConfigurationSettings class and assign it to the aConfig variable, so how could you possibly access an instance member when you haven't created an instance? What the warning message is saying is that AppSettings is a Shared member, so the compiler is simply going to ignore your variable and access it via the class, which you should be doing in the first place, i.e.:
vb.net Code:
Dim strServerName As String = Configuration.ConfigurationSettings.AppSettings("ServerName")
That said, the ConfigurationSettings class is obsolete in .NET 2.0. You should start using the ConfigurationManager class, which the compiler would also have told you.
Note that the reason you didn't see this warning in VB.NET 2003 is not that your code wasn't wrong. It's just that the compiler fixed the problem silently rather than pointing out your mistake and letting you fix it.
-
May 2nd, 2008, 01:03 AM
#3
Thread Starter
Hyperactive Member
Re: [2005]Problem with my COnfiguration Settings
hmmmmm....i see...but jm is there any way how to correct this warning?it doesn't run on my program and i couldn't connect to my configurationSettings. HOw can I use ConfigurationManager jm?
-
May 2nd, 2008, 01:28 AM
#4
Re: [2005]Problem with my COnfiguration Settings
Well, I've already shown you exactly how to clear the warning from your existing code. The message says that it's a Shared member and Shared members are accessed via the type, not an instance of the type. As for using the ConfigurationManager class, have you made any attempt to read the documentation?
-
May 2nd, 2008, 03:08 AM
#5
Thread Starter
Hyperactive Member
Re: [2005]Problem with my COnfiguration Settings
Not yet jm but i will try to..Thanks again jm...Thanks for the info..Have a nice day to you...God Bless..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|