Results 1 to 4 of 4

Thread: [RESOLVED] Import namespace help needed

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    101

    Resolved [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:
    1. 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?

  2. #2
    Member
    Join Date
    Jun 2005
    Posts
    61

    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:
    1. Dim startTable As IDictionary = CType(System.Configuration.ConfigurationSettings.GetConfig("start"), IDictionary)

  3. #3
    Frenzied Member conipto's Avatar
    Join Date
    Jun 2005
    Location
    Chicago
    Posts
    1,175

    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
    Hate Adobe Acrobat? My Codebank Sumbissions - Easy CodeDom Expression evaluator: (VB / C# ) -- C# Scrolling Text Display

    I Like to code when drunk. Don't say you weren't warned.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    101

    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
  •  



Click Here to Expand Forum to Full Width