Namespace confusion

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tshad

    Namespace confusion

    Using VS 2008, I have a project that uses the dll from another project.

    The Namespace is MyFunctions, with a class of DbObject. The beginning of
    the code is:
    *************** ************
    Imports System
    Imports System.Data
    Imports System.Data.Sql Client

    Namespace MyFunctions

    Public Class DbObject
    *************** ***********

    The Project, class vb file, and dll are called MyFunctions.

    In my code, I have to:

    Imports MyFunctions.MyF unctions

    To get this to work:

    Dim myDbObject As New DbObject("a test")


    Why don't I need:

    Imports MyFunctions

    How would I change the project to allow me to use only the Namespace?

    Thanks,

    Tom


  • kimiraikkonen

    #2
    Re: Namespace confusion

    On Sep 14, 8:08 am, "tshad" <t...@dslextrem e.comwrote:
    Using VS 2008, I have a project that uses the dll from another project.
    >
    The Namespace is MyFunctions, with a class of DbObject.  The beginning of
    the code is:
    *************** ************
    Imports System
    Imports System.Data
    Imports System.Data.Sql Client
    >
    Namespace MyFunctions
    >
      Public Class DbObject
    *************** ***********
    >
    The Project, class vb file, and dll are called MyFunctions.
    >
    In my code, I have to:
    >
    Imports MyFunctions.MyF unctions
    >
    To get this to work:
    >
        Dim myDbObject As New DbObject("a test")
    >
    Why don't I need:
    >
    Imports MyFunctions
    When you use "MyFunctions.My Functions", it sounds like you have 2
    nested namespaces with the same name which is not necessary for
    readablity. If DbObject is located under MyFunctions, you'd better
    remove second MyFunctions namespace and revise your assembly as:

    Imports MyFunctions

    Dim myDbObject As New DbObject("a test")
    '.....Here actually it's same with without "Imports"
    ' Dim myDbObject As New MyFunctions.DbO bject("a test")

    HTH,

    Onur Güzel

    Comment

    • tshad

      #3
      Re: Namespace confusion

      kimiraikkonen wrote:
      On Sep 14, 8:08 am, "tshad" <t...@dslextrem e.comwrote:
      >Using VS 2008, I have a project that uses the dll from another
      >project.
      >>
      >The Namespace is MyFunctions, with a class of DbObject. The
      >beginning of the code is:
      >************** *************
      >Imports System
      >Imports System.Data
      >Imports System.Data.Sql Client
      >>
      >Namespace MyFunctions
      >>
      >Public Class DbObject
      >************** ************
      >>
      >The Project, class vb file, and dll are called MyFunctions.
      >>
      >In my code, I have to:
      >>
      >Imports MyFunctions.MyF unctions
      >>
      >To get this to work:
      >>
      >Dim myDbObject As New DbObject("a test")
      >>
      >Why don't I need:
      >>
      >Imports MyFunctions
      >
      When you use "MyFunctions.My Functions", it sounds like you have 2
      nested namespaces with the same name which is not necessary for
      readablity. If DbObject is located under MyFunctions, you'd better
      remove second MyFunctions namespace and revise your assembly as:
      >
      I seem to have this but not sure why.

      When I created the Class Library project, it created 2 folders :

      MyFunctions <----Folder
      Myfunctions <--- Folder
      MyFunctions.sln
      MyFunction.suo

      VS puts the code files in the 2nd MyFunctions folder.

      My files are set up as I show (with one namespace).

      In my web site, I referenced the .dll from this project and it is the one
      that thinks there are 2 namespaces. Imports MyFunctions won't work because
      it thinks there are 2 namespaces.

      Thanks,

      Tom
      Imports MyFunctions
      >
      Dim myDbObject As New DbObject("a test")
      '.....Here actually it's same with without "Imports"
      ' Dim myDbObject As New MyFunctions.DbO bject("a test")
      >
      HTH,
      >
      Onur Güzel

      Comment

      • =?Utf-8?B?RGF2aWQgQW50b24=?=

        #4
        RE: Namespace confusion

        In your project properties, see what you have for 'Root namespace'. All
        classes in your VB project are in this namespace. You'll find that it's
        probably set to "MyFunction s". Either clear the root namespace or avoid
        adding the namespace explicitly in your code files.
        --
        Source code converters: Convert between C#, C++, Java, and VB with the most accurate and reliable source code converters

        C++ to C#
        C++ to VB
        C++ to Java
        VB & C# to Java
        Java to VB & C#
        Instant C#: VB to C#
        Instant VB: C# to VB
        Instant C++: VB, C#, or Java to C++/CLI


        "tshad" wrote:
        Using VS 2008, I have a project that uses the dll from another project.
        >
        The Namespace is MyFunctions, with a class of DbObject. The beginning of
        the code is:
        *************** ************
        Imports System
        Imports System.Data
        Imports System.Data.Sql Client
        >
        Namespace MyFunctions
        >
        Public Class DbObject
        *************** ***********
        >
        The Project, class vb file, and dll are called MyFunctions.
        >
        In my code, I have to:
        >
        Imports MyFunctions.MyF unctions
        >
        To get this to work:
        >
        Dim myDbObject As New DbObject("a test")
        >
        >
        Why don't I need:
        >
        Imports MyFunctions
        >
        How would I change the project to allow me to use only the Namespace?
        >
        Thanks,
        >
        Tom
        >
        >
        >

        Comment

        • tshad

          #5
          Re: Namespace confusion

          David Anton wrote:
          In your project properties, see what you have for 'Root namespace'.
          All classes in your VB project are in this namespace. You'll find
          that it's probably set to "MyFunction s". Either clear the root
          namespace or avoid adding the namespace explicitly in your code files.
          >
          That was the problem.

          But why would VS work this way?

          I don't think I have seen anywhere where it says to do this.

          You would normally set the namespace in your file as part of the code. Why
          would the Project add another?

          Thanks,

          Tom
          >Using VS 2008, I have a project that uses the dll from another
          >project.
          >>
          >The Namespace is MyFunctions, with a class of DbObject. The
          >beginning of the code is:
          >************** *************
          >Imports System
          >Imports System.Data
          >Imports System.Data.Sql Client
          >>
          >Namespace MyFunctions
          >>
          > Public Class DbObject
          >************** ************
          >>
          >The Project, class vb file, and dll are called MyFunctions.
          >>
          >In my code, I have to:
          >>
          >Imports MyFunctions.MyF unctions
          >>
          >To get this to work:
          >>
          > Dim myDbObject As New DbObject("a test")
          >>
          >>
          >Why don't I need:
          >>
          >Imports MyFunctions
          >>
          >How would I change the project to allow me to use only the Namespace?
          >>
          >Thanks,
          >>
          >Tom

          Comment

          • Jack Jackson

            #6
            Re: Namespace confusion

            On Sun, 14 Sep 2008 10:18:13 -0700, "tshad" <tfs@dslextreme .com>
            wrote:
            >David Anton wrote:
            >In your project properties, see what you have for 'Root namespace'.
            >All classes in your VB project are in this namespace. You'll find
            >that it's probably set to "MyFunction s". Either clear the root
            >namespace or avoid adding the namespace explicitly in your code files.
            >>
            >That was the problem.
            >
            >But why would VS work this way?
            >
            >I don't think I have seen anywhere where it says to do this.
            >
            >You would normally set the namespace in your file as part of the code. Why
            >would the Project add another?
            I would not normally add the Namespace in every file, I would have the
            root NameSpace specified in the project so that I don't have to put it
            in every file in the project.

            Comment

            • Cor Ligthert[MVP]

              #7
              Re: Namespace confusion

              Tom,

              Why are you all the time calling the behaviour of Java developers (and
              languages very much based on that) normal behaviour. Mostly I use in C# only
              one namespace in a solution, not even a project, and it gives me only a lot
              of time correcting those (by the way, there is as well a default namespace
              in the project properties in C#, only it does not work as fine as in VB).

              You consequently are debating that you want that the VB languages need as
              much typing as languages direct derived from C, while you only are
              referening to those languages without giving any other reason.

              Don't forget that C# is a typical scholar languages. Where things need to be
              easy to explain as you don't know the functions yet.

              Just my opinion.

              Cor


              "tshad" <tfs@dslextreme .comschreef in bericht
              news:eM9He3oFJH A.5440@TK2MSFTN GP03.phx.gbl...
              David Anton wrote:
              >In your project properties, see what you have for 'Root namespace'.
              >All classes in your VB project are in this namespace. You'll find
              >that it's probably set to "MyFunction s". Either clear the root
              >namespace or avoid adding the namespace explicitly in your code files.
              >>
              That was the problem.
              >
              But why would VS work this way?
              >
              I don't think I have seen anywhere where it says to do this.
              >
              You would normally set the namespace in your file as part of the code.
              Why would the Project add another?
              >
              Thanks,
              >
              Tom
              >>Using VS 2008, I have a project that uses the dll from another
              >>project.
              >>>
              >>The Namespace is MyFunctions, with a class of DbObject. The
              >>beginning of the code is:
              >>************* **************
              >>Imports System
              >>Imports System.Data
              >>Imports System.Data.Sql Client
              >>>
              >>Namespace MyFunctions
              >>>
              >> Public Class DbObject
              >>************* *************
              >>>
              >>The Project, class vb file, and dll are called MyFunctions.
              >>>
              >>In my code, I have to:
              >>>
              >>Imports MyFunctions.MyF unctions
              >>>
              >>To get this to work:
              >>>
              >> Dim myDbObject As New DbObject("a test")
              >>>
              >>>
              >>Why don't I need:
              >>>
              >>Imports MyFunctions
              >>>
              >>How would I change the project to allow me to use only the Namespace?
              >>>
              >>Thanks,
              >>>
              >>Tom
              >
              >

              Comment

              • James Hahn

                #8
                Re: Namespace confusion

                The root namespace is supposed to be something that makes the full name
                unique - there could be many MyFunctions but probably only one
                tshad.MyFunctio ns.

                "tshad" <tfs@dslextreme .comwrote in message
                news:eM9He3oFJH A.5440@TK2MSFTN GP03.phx.gbl...
                David Anton wrote:
                >In your project properties, see what you have for 'Root namespace'.
                >All classes in your VB project are in this namespace. You'll find
                >that it's probably set to "MyFunction s". Either clear the root
                >namespace or avoid adding the namespace explicitly in your code files.
                >>
                That was the problem.
                >
                But why would VS work this way?
                >
                I don't think I have seen anywhere where it says to do this.
                >
                You would normally set the namespace in your file as part of the code.
                Why would the Project add another?
                >
                Thanks,
                >
                Tom

                Comment

                • tshad

                  #9
                  Re: Namespace confusion


                  "Cor Ligthert[MVP]" <notmyfirstname @planet.nlwrote in message
                  news:BE2B9628-EDE2-403F-BA25-9A6910B24A2A@mi crosoft.com...
                  Tom,
                  >
                  Why are you all the time calling the behaviour of Java developers (and
                  languages very much based on that) normal behaviour.
                  Didn't realize I was. I assumed (and yes I know the problem with that :) )
                  that it was normal to do this. But that was because in my old job, I did
                  all my coding (VB and C#) in Dreamweaver so I had no project that would put
                  the namespace in it. This meant I would have to do this.

                  Also, many of the sample code I have seen on the net (VB or C#) had the
                  namespace in the source.
                  >Mostly I use in C# only one namespace in a solution, not even a project,
                  >and it gives me only a lot of time correcting those (by the way, there is
                  >as well a default namespace in the project properties in C#, only it does
                  >not work as fine as in VB).
                  >
                  You consequently are debating that you want that the VB languages need as
                  much typing as languages direct derived from C, while you only are
                  referening to those languages without giving any other reason.
                  >
                  I don't think I do that. I personally like both languages and the
                  differences tend not to be the languages themselves but the implementations
                  of the languages in VS.

                  I know that I did make this statement in another thread:
                  *************** *************** ***************
                  Option Strict On doesn't fix every quirk in VB.NET... ;)
                  I agree.

                  and the same thing about C#. We have these discussions at work all the
                  time. Why doesn't C# to this like VB does or why doesn't VB do that like C#
                  does.
                  *************** *************** *************** *******

                  My point here was that at work the people that like VB are constantly
                  complaining when they have to work on C# projects that VB does this or that
                  better.

                  And when people that like C# are constantly complaining when they have to
                  work on VB projects that C# does this or that better.

                  I just think it is funny.

                  I happen to like the Case sensitivity of C# because it I can use the same
                  names for different things (camel case for memory variables, pascal case for
                  functions and upper case for constants for example). Others hate it.

                  Tom
                  Don't forget that C# is a typical scholar languages. Where things need to
                  be easy to explain as you don't know the functions yet.
                  >
                  Just my opinion.
                  >
                  Cor
                  >
                  >
                  "tshad" <tfs@dslextreme .comschreef in bericht
                  news:eM9He3oFJH A.5440@TK2MSFTN GP03.phx.gbl...
                  >David Anton wrote:
                  >>In your project properties, see what you have for 'Root namespace'.
                  >>All classes in your VB project are in this namespace. You'll find
                  >>that it's probably set to "MyFunction s". Either clear the root
                  >>namespace or avoid adding the namespace explicitly in your code files.
                  >>>
                  >That was the problem.
                  >>
                  >But why would VS work this way?
                  >>
                  >I don't think I have seen anywhere where it says to do this.
                  >>
                  >You would normally set the namespace in your file as part of the code.
                  >Why would the Project add another?
                  >>
                  >Thanks,
                  >>
                  >Tom
                  >>>Using VS 2008, I have a project that uses the dll from another
                  >>>project.
                  >>>>
                  >>>The Namespace is MyFunctions, with a class of DbObject. The
                  >>>beginning of the code is:
                  >>>************ ***************
                  >>>Imports System
                  >>>Imports System.Data
                  >>>Imports System.Data.Sql Client
                  >>>>
                  >>>Namespace MyFunctions
                  >>>>
                  >>> Public Class DbObject
                  >>>************ **************
                  >>>>
                  >>>The Project, class vb file, and dll are called MyFunctions.
                  >>>>
                  >>>In my code, I have to:
                  >>>>
                  >>>Imports MyFunctions.MyF unctions
                  >>>>
                  >>>To get this to work:
                  >>>>
                  >>> Dim myDbObject As New DbObject("a test")
                  >>>>
                  >>>>
                  >>>Why don't I need:
                  >>>>
                  >>>Imports MyFunctions
                  >>>>
                  >>>How would I change the project to allow me to use only the Namespace?
                  >>>>
                  >>>Thanks,
                  >>>>
                  >>>Tom
                  >>
                  >>
                  >

                  Comment

                  Working...