|
-
Jan 13th, 2006, 02:31 PM
#1
Thread Starter
Lively Member
[RESOLVED] Import namespace help needed
Hi all,
In my startup module for my app I'm trying to accomplish a couple of things and I'm running into an imports error. The first thing I'm doing is checking for a valid internet connection. The next thing is reading the app.config file.
I'm Importing Systems.Net to allow the checking for the internet. The problem is when I add the systems.net import I get an error in the code for the config file:
VB Code:
Dim startTable as IDictionary = CType(Configuration.ConfigurationSettings.GetConfig("start"),IDictionary)
I'm getting "ConfigurationSettings is not a member of Configuration" (blue squiggly line under Configuration.ConfigurationSettings)
However, if I remove the Imports System.Net reference then the Configuration.ConfigureSettings error goes away.
In msdn help for "Imports Statement" it says: It is not permitted to define a member at module level with the same name as an import alias.
Maybe this has something to do with it?
Any ideas why this would be happening?
-
Jan 13th, 2006, 02:43 PM
#2
Member
Re: Import namespace help needed
You need to add System in front of Configuration. The reason is because System.Net has a configuration class also, so you have to qualify the namespace.
VB Code:
Dim startTable As IDictionary = CType(System.Configuration.ConfigurationSettings.GetConfig("start"), IDictionary)
-
Jan 13th, 2006, 02:48 PM
#3
Re: Import namespace help needed
To further expand on dreamr's answer, the reason is this:
When you add an imports statement, you allow yourself to not need to qualify the namespace. For example:
IO.StreamReader is valid in a program, but if you use a
Imports System.IO
You only need to say
StreamReader
because you've told the compiler that you are using the IO namespace.
However, let's say you have a custom class with your own streamreaders called MyIO..
Then, you can say
MyIO.StreamReader
and
IO.StreamReader
but if your imports statements include both namespaces..
Imports MyIO
Imports System.IO
StreamReader becomes ambiguous, because it could mean either class of streamreader. So, you have to tell the compiler WHICH streamreader you mean.
Bill
-
Jan 13th, 2006, 02:55 PM
#4
Thread Starter
Lively Member
Re: Import namespace help needed
You guys are awesome! Thank you so much for the help and explanation!
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
|