Global namespace problem

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

    Global namespace problem

    I have 2 external assemblies A1 and A2 that both define class X in the global
    namespace. I need to use both assemblies in my VB project but the names X are
    ambiguous. How can I get around this problem?

    Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this syntax
    does not compile).

    Or can I change the name X in the Imports directive? Again the problem is
    how do I refer to the 2 different X'es in assemblies A1 and A2:

    Imports A1_X = A1.X ' Does not compile

    BTW, is there any way to explicitly refer to the global namespace, like C++
    ::?

    Any bright ideas out there?
  • Armin Zingler

    #2
    Re: Global namespace problem

    "anders" <anders@discuss ions.microsoft. com> schrieb[color=blue]
    > I have 2 external assemblies A1 and A2 that both define class X in
    > the global namespace. I need to use both assemblies in my VB project
    > but the names X are ambiguous. How can I get around this problem?
    >
    > Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this
    > syntax does not compile).
    >
    > Or can I change the name X in the Imports directive? Again the
    > problem is how do I refer to the 2 different X'es in assemblies A1
    > and A2:
    >
    > Imports A1_X = A1.X ' Does not compile
    >
    > BTW, is there any way to explicitly refer to the global namespace,
    > like C++ ::?
    >
    > Any bright ideas out there?[/color]


    Did you leave the "root namespace" of the two assemblies empty? If you
    didn't, you can use the full qualified name.


    Armin

    Comment

    • Dennis

      #3
      Re: Global namespace problem

      Armin, how do you set the root namespace? I get very confused regarding the
      namespace heirchy
      --
      Dennis in Houston


      "Armin Zingler" wrote:
      [color=blue]
      > "anders" <anders@discuss ions.microsoft. com> schrieb[color=green]
      > > I have 2 external assemblies A1 and A2 that both define class X in
      > > the global namespace. I need to use both assemblies in my VB project
      > > but the names X are ambiguous. How can I get around this problem?
      > >
      > > Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this
      > > syntax does not compile).
      > >
      > > Or can I change the name X in the Imports directive? Again the
      > > problem is how do I refer to the 2 different X'es in assemblies A1
      > > and A2:
      > >
      > > Imports A1_X = A1.X ' Does not compile
      > >
      > > BTW, is there any way to explicitly refer to the global namespace,
      > > like C++ ::?
      > >
      > > Any bright ideas out there?[/color]
      >
      >
      > Did you leave the "root namespace" of the two assemblies empty? If you
      > didn't, you can use the full qualified name.
      >
      >
      > Armin
      >
      >[/color]

      Comment

      • anders

        #4
        Re: Global namespace problem

        Can you elaborate, please. You have lost me!

        "Armin Zingler" wrote:
        [color=blue]
        > "anders" <anders@discuss ions.microsoft. com> schrieb[color=green]
        > > I have 2 external assemblies A1 and A2 that both define class X in
        > > the global namespace. I need to use both assemblies in my VB project
        > > but the names X are ambiguous. How can I get around this problem?
        > >
        > > Is there a way to refer to the assembly, f.ex. A1.X and A2.X (this
        > > syntax does not compile).
        > >
        > > Or can I change the name X in the Imports directive? Again the
        > > problem is how do I refer to the 2 different X'es in assemblies A1
        > > and A2:
        > >
        > > Imports A1_X = A1.X ' Does not compile
        > >
        > > BTW, is there any way to explicitly refer to the global namespace,
        > > like C++ ::?
        > >
        > > Any bright ideas out there?[/color]
        >
        >
        > Did you leave the "root namespace" of the two assemblies empty? If you
        > didn't, you can use the full qualified name.
        >
        >
        > Armin
        >
        >[/color]

        Comment

        • Armin Zingler

          #5
          Re: Global namespace problem

          "anders" <anders@discuss ions.microsoft. com> schrieb[color=blue][color=green]
          > > "anders" <anders@discuss ions.microsoft. com> schrieb[color=darkred]
          > > > I have 2 external assemblies A1 and A2 that both define class X
          > > > in the global namespace. I need to use both assemblies in my VB
          > > > project but the names X are ambiguous. How can I get around this
          > > > problem?
          > > >
          > > > Is there a way to refer to the assembly, f.ex. A1.X and A2.X
          > > > (this syntax does not compile).
          > > >
          > > > Or can I change the name X in the Imports directive? Again the
          > > > problem is how do I refer to the 2 different X'es in assemblies
          > > > A1 and A2:
          > > >
          > > > Imports A1_X = A1.X ' Does not compile
          > > >
          > > > BTW, is there any way to explicitly refer to the global
          > > > namespace, like C++ ::?
          > > >
          > > > Any bright ideas out there?[/color]
          > >
          > >
          > > Did you leave the "root namespace" of the two assemblies empty? If
          > > you didn't, you can use the full qualified name.[/color]
          >
          > Can you elaborate, please. You have lost me!
          >[/color]

          In each assembly, you can set the "root namespace" in the project
          properties. That's the namespace all classes and namespaces are placed in.
          If you left them (in both projects) empty, you probably really have got a
          problem because the full qualified name is the same. If you didn't leave it
          empty, you could use the full qualified name to specify the class. If A1 ist
          the root namespace of assembly A1, then A1.X is the full qualified class
          name of the class in assembly A1.


          Armni

          Comment

          • Phill.  W

            #6
            Re: Global namespace problem

            "anders" <anders@discuss ions.microsoft. com> wrote in message
            news:E4C989FA-B950-441E-93E6-2CE681736479@mi crosoft.com...[color=blue]
            > I have 2 external assemblies A1 and A2 that both define class X in
            > the global namespace. I need to use both assemblies in my VB project
            > but the names X are ambiguous. How can I get around this problem?[/color]

            Either fully-qualify all references to each class, as in

            sData = NS1.NS2.NS3.X.S tringMethod()
            sData = NS4.NS5.NS6.X.S tringMethod()

            or change the Imports statements so add your own "alias", as in

            Imports A1=NS1.NS2.NS3
            Imports A2=NS4.NS5.NS6

            sData = A1.X.StringMeth od()
            sData = A2.X.StringMeth od()

            (I use the same thing with the VisualBasic namespace, just to jog my
            memory about the potential differences, as in

            sItems = VB.Split( "string with line breaks", vbCrLf )

            HTH,
            Phill W.


            Comment

            • Dennis

              #7
              Re: Global namespace problem

              I found that if I don't specifically provide a root namespace, then when I
              create a new project, the name of the directory if used.
              --
              Dennis in Houston


              "Phill. W" wrote:
              [color=blue]
              > "anders" <anders@discuss ions.microsoft. com> wrote in message
              > news:E4C989FA-B950-441E-93E6-2CE681736479@mi crosoft.com...[color=green]
              > > I have 2 external assemblies A1 and A2 that both define class X in
              > > the global namespace. I need to use both assemblies in my VB project
              > > but the names X are ambiguous. How can I get around this problem?[/color]
              >
              > Either fully-qualify all references to each class, as in
              >
              > sData = NS1.NS2.NS3.X.S tringMethod()
              > sData = NS4.NS5.NS6.X.S tringMethod()
              >
              > or change the Imports statements so add your own "alias", as in
              >
              > Imports A1=NS1.NS2.NS3
              > Imports A2=NS4.NS5.NS6
              >
              > sData = A1.X.StringMeth od()
              > sData = A2.X.StringMeth od()
              >
              > (I use the same thing with the VisualBasic namespace, just to jog my
              > memory about the potential differences, as in
              >
              > sItems = VB.Split( "string with line breaks", vbCrLf )
              >
              > HTH,
              > Phill W.
              >
              >
              >[/color]

              Comment

              • anders

                #8
                Re: Global namespace problem

                A1 and A2 are OEM products so I don't have the source code or project files
                to fiddle with. This begins to look like a serious problem in .NET languages.
                The VB.NET Imports directive gives you the possibility to resolve name
                clashes between named namespaces but NOT clashes within the global namespace!

                I also looked into C# and Managed C++ and could not find any solution to
                this problem.

                "Armin Zingler" wrote:
                [color=blue]
                > "anders" <anders@discuss ions.microsoft. com> schrieb[color=green][color=darkred]
                > > > "anders" <anders@discuss ions.microsoft. com> schrieb
                > > > > I have 2 external assemblies A1 and A2 that both define class X
                > > > > in the global namespace. I need to use both assemblies in my VB
                > > > > project but the names X are ambiguous. How can I get around this
                > > > > problem?
                > > > >
                > > > > Is there a way to refer to the assembly, f.ex. A1.X and A2.X
                > > > > (this syntax does not compile).
                > > > >
                > > > > Or can I change the name X in the Imports directive? Again the
                > > > > problem is how do I refer to the 2 different X'es in assemblies
                > > > > A1 and A2:
                > > > >
                > > > > Imports A1_X = A1.X ' Does not compile
                > > > >
                > > > > BTW, is there any way to explicitly refer to the global
                > > > > namespace, like C++ ::?
                > > > >
                > > > > Any bright ideas out there?
                > > >
                > > >
                > > > Did you leave the "root namespace" of the two assemblies empty? If
                > > > you didn't, you can use the full qualified name.[/color]
                > >
                > > Can you elaborate, please. You have lost me!
                > >[/color]
                >
                > In each assembly, you can set the "root namespace" in the project
                > properties. That's the namespace all classes and namespaces are placed in.
                > If you left them (in both projects) empty, you probably really have got a
                > problem because the full qualified name is the same. If you didn't leave it
                > empty, you could use the full qualified name to specify the class. If A1 ist
                > the root namespace of assembly A1, then A1.X is the full qualified class
                > name of the class in assembly A1.
                >
                >
                > Armni
                >
                >[/color]

                Comment

                • anders

                  #9
                  Re: Global namespace problem

                  You don't seem to answer my question. How do you fully qualify X which is in
                  the global namespace of both assemblies A1 and A2?

                  "Phill. W" wrote:
                  [color=blue]
                  > "anders" <anders@discuss ions.microsoft. com> wrote in message
                  > news:E4C989FA-B950-441E-93E6-2CE681736479@mi crosoft.com...[color=green]
                  > > I have 2 external assemblies A1 and A2 that both define class X in
                  > > the global namespace. I need to use both assemblies in my VB project
                  > > but the names X are ambiguous. How can I get around this problem?[/color]
                  >
                  > Either fully-qualify all references to each class, as in
                  >
                  > sData = NS1.NS2.NS3.X.S tringMethod()
                  > sData = NS4.NS5.NS6.X.S tringMethod()
                  >
                  > or change the Imports statements so add your own "alias", as in
                  >
                  > Imports A1=NS1.NS2.NS3
                  > Imports A2=NS4.NS5.NS6
                  >
                  > sData = A1.X.StringMeth od()
                  > sData = A2.X.StringMeth od()
                  >
                  > (I use the same thing with the VisualBasic namespace, just to jog my
                  > memory about the potential differences, as in
                  >
                  > sItems = VB.Split( "string with line breaks", vbCrLf )
                  >
                  > HTH,
                  > Phill W.
                  >
                  >
                  >[/color]

                  Comment

                  • Armin Zingler

                    #10
                    Re: Global namespace problem

                    "anders" <anders@discuss ions.microsoft. com> schrieb[color=blue][color=green]
                    > >
                    > > In each assembly, you can set the "root namespace" in the project
                    > > properties. That's the namespace all classes and namespaces are
                    > > placed in. If you left them (in both projects) empty, you probably
                    > > really have got a problem because the full qualified name is the
                    > > same. If you didn't leave it empty, you could use the full
                    > > qualified name to specify the class. If A1 ist the root namespace
                    > > of assembly A1, then A1.X is the full qualified class name of the
                    > > class in assembly A1.
                    > >[/color]
                    > A1 and A2 are OEM products so I don't have the source code or
                    > project files to fiddle with. This begins to look lik
                    > easeriousproble min.NETlanguage s. The VB.NET Imports directive gives
                    > you the possibility to resolve name clashes between named namespaces
                    > but NOT clashes within the global namespace!
                    >
                    > I also looked into C# and Managed C++ and could not find any
                    > solution to this problem.[/color]


                    I do not really see the problem. I do not even have the possibilty to set
                    references to two assemblies containing conflicting class names because I
                    get this error:

                    "bla\ClassLibra ry2\Class1.vb(1 ): class "Class1" and class "Class1", defined
                    in "bla\ClassLibra ry1\Class1.vb", conflict in namespace "<Default>" "

                    You get this message if you create a new project, add two new
                    classlibraries, delete the root namespace in both libraries and try to set a
                    reference from the main project to both classlibraries.


                    Are you sure that the classes are not contained in a namespace in both
                    assemblies? Have a look @ the object browser.



                    Armin

                    Comment

                    • Phill.  W

                      #11
                      Re: Global namespace problem

                      Define "OEM products".

                      If these are commerical products that are shipping /without/ using
                      well-defined Namespaces, I'd think long and hard before making use
                      of them.

                      If you have no other recourse, you may have to write your own,
                      (properly Namespaced) "wrapper" assembly around one or other
                      of them, exposing all the same properties, method, etc.

                      Regards,
                      Phill W.

                      "anders" <anders@discuss ions.microsoft. com> wrote in message
                      news:8F069137-F01E-4A03-B709-C8466DD95B35@mi crosoft.com...[color=blue]
                      > A1 and A2 are OEM products so I don't have the source code or
                      > project files to fiddle with. This begins to look like a serious problem
                      > in .NET languages.[/color]
                      [color=blue]
                      > "Armin Zingler" wrote:
                      >[color=green]
                      > > "anders" <anders@discuss ions.microsoft. com> schrieb[color=darkred]
                      > > > > "anders" <anders@discuss ions.microsoft. com> schrieb
                      > > > > > I have 2 external assemblies A1 and A2 that both define class X
                      > > > > > in the global namespace. I need to use both assemblies in my VB
                      > > > > > project but the names X are ambiguous. How can I get around this
                      > > > > > problem?
                      > > > > >
                      > > > > > Is there a way to refer to the assembly, f.ex. A1.X and A2.X
                      > > > > > (this syntax does not compile).
                      > > > > >
                      > > > > > Or can I change the name X in the Imports directive? Again the
                      > > > > > problem is how do I refer to the 2 different X'es in assemblies
                      > > > > > A1 and A2:
                      > > > > >
                      > > > > > Imports A1_X = A1.X ' Does not compile
                      > > > > >
                      > > > > > BTW, is there any way to explicitly refer to the global
                      > > > > > namespace, like C++ ::?
                      > > > > >
                      > > > > > Any bright ideas out there?
                      > > > >
                      > > > >
                      > > > > Did you leave the "root namespace" of the two assemblies empty? If
                      > > > > you didn't, you can use the full qualified name.
                      > > >
                      > > > Can you elaborate, please. You have lost me!
                      > > >[/color]
                      > >
                      > > In each assembly, you can set the "root namespace" in the project
                      > > properties. That's the namespace all classes and namespaces are placed[/color][/color]
                      in.[color=blue][color=green]
                      > > If you left them (in both projects) empty, you probably really have got[/color][/color]
                      a[color=blue][color=green]
                      > > problem because the full qualified name is the same. If you didn't leave[/color][/color]
                      it[color=blue][color=green]
                      > > empty, you could use the full qualified name to specify the class. If A1[/color][/color]
                      ist[color=blue][color=green]
                      > > the root namespace of assembly A1, then A1.X is the full qualified class
                      > > name of the class in assembly A1.
                      > >
                      > >
                      > > Armni
                      > >
                      > >[/color][/color]


                      Comment

                      Working...