Home All Groups Group Topic Archive Search About

Ambiguous Name In Mamespace?

Author
4 Sep 2006 8:54 PM
Arpan
The following code exists in a class file named "Users.vb":

Namespace Users
    Public Class UserDetails
        Public FirstName As String
        Public LastName As String
        Public UserName As String
        Public Password As String
        Public UserID As String
    End Class

    Public Class User
        Public Function GetDetails(ByVal UserID As Integer) As
UserDetails
            Dim uDetails As UserDetails

            uDetails = New UserDetails
            .................
            .................
            Return uDetails
        End Function
    End Class
End Namespace

The above code successfully gets compiled into a DLL & the ASPX page
that imports the above namespace executes without any errors as well
but Visual Web Developer 2005 Express Edition underlines the word
"UserDetails" at all the places within the GetDetails function
(including the function declaration line) indicating a compiler error
that says:

'UserDetails' is ambiguous in the namespace 'Users'.

What's causing this compiler error in VWD 2005?

Thanks,

Arpan

Author
5 Sep 2006 6:30 AM
Laurent Bugnion
Hi,

Arpan wrote:

<snip>

Show quote
> The above code successfully gets compiled into a DLL & the ASPX page
> that imports the above namespace executes without any errors as well
> but Visual Web Developer 2005 Express Edition underlines the word
> "UserDetails" at all the places within the GetDetails function
> (including the function declaration line) indicating a compiler error
> that says:
>
> 'UserDetails' is ambiguous in the namespace 'Users'.
>
> What's causing this compiler error in VWD 2005?
>
> Thanks,
>
> Arpan

Please allow me to write the example in C#, as I am not fluent in VB.NET
and wouldn't want to write wrong code.

"Ambiguous" in that case means that a class with the name "UserDetails"
is defined in more than one namespace.

The unique name for a class is formed using the full namespace hierarchy
and the class name.

example: System.Web.UI.Control or System.Windows.Forms.Control

However, the compiler allows implicit reference to classes using their
name only. This might cause a problem if you do this:

using System.Web.UI; // Corresponds to VB Import
using System.Windows.Forms;


and you then try to use the Control class. In that case, the compiler is
not sure which "Control" you mean, and will create this warning. In
these cases, it's best to use the full name to reference the class, for
example:

System.Web.UI.Control myControl = new System.Web.UI.Control();

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Author
5 Sep 2006 10:43 AM
Arpan
Thanks, Laurent.....your advice has taken care of the problem.

Regards,

Arpan

Laurent Bugnion wrote:
Show quote
> Hi,
>
> Arpan wrote:
>
> <snip>
>
> > The above code successfully gets compiled into a DLL & the ASPX page
> > that imports the above namespace executes without any errors as well
> > but Visual Web Developer 2005 Express Edition underlines the word
> > "UserDetails" at all the places within the GetDetails function
> > (including the function declaration line) indicating a compiler error
> > that says:
> >
> > 'UserDetails' is ambiguous in the namespace 'Users'.
> >
> > What's causing this compiler error in VWD 2005?
> >
> > Thanks,
> >
> > Arpan
>
> Please allow me to write the example in C#, as I am not fluent in VB.NET
> and wouldn't want to write wrong code.
>
> "Ambiguous" in that case means that a class with the name "UserDetails"
> is defined in more than one namespace.
>
> The unique name for a class is formed using the full namespace hierarchy
> and the class name.
>
> example: System.Web.UI.Control or System.Windows.Forms.Control
>
> However, the compiler allows implicit reference to classes using their
> name only. This might cause a problem if you do this:
>
> using System.Web.UI; // Corresponds to VB Import
> using System.Windows.Forms;
>
>
> and you then try to use the Control class. In that case, the compiler is
> not sure which "Control" you mean, and will create this warning. In
> these cases, it's best to use the full name to reference the class, for
> example:
>
> System.Web.UI.Control myControl = new System.Web.UI.Control();
>
> HTH,
> Laurent
> --
> Laurent Bugnion, GalaSoft
> Software engineering: http://www.galasoft-LB.ch
> Private/Malaysia: http://mypage.bluewin.ch/lbugnion
> Support children in Calcutta: http://www.calcutta-espoir.ch
Author
5 Sep 2006 11:15 AM
Arpan
I am sorry, Laurent, but after posting my earlier response, I realized
that the ambiguous problem still exists even if I change the
"UserDetails" class name to, say, "a1b2c3d4" (without the quotes) i.e.
the code now looks like this:

Namespace Users
    Public Class a1b2c3d4
        Public FirstName As String
        Public LastName As String
        Public UserName As String
        Public Password As String
        Public UserID As String
    End Class

    Public Class User
        Public Function GetDetails(ByVal UserID As Integer) As a1b2c3d4
            Dim uDetails As a1b2c3d4

            uDetails = New a1b2c3d4
            .................
            .................
            Return uDetails
        End Function
    End Class
End Namespace

then VWD 2005 still generates the same compiler error i.e.

'a1b2c3d4' is ambiguous in the namespace 'Users'.

Now I don't think the .NET Framework has any namespace that defines a
class named "a1b2c3d4". Neither am I definng "a1b2c3d4" as a class name
in any namespaces that I have created. So why still this error?

Even if I prefix the class name ("a1b2c3d4") with the namespace "Users"
using the dot notation, as you suggested, in the above code i.e.
replace all instances of the word "a1b2c3d4" in the class "User" with
"Users.a1b2c3d4", then VWD still generates the ambiguous class name
error.

What would you suggest now?

Thanks once again,

Regards,

Arpan

Arpan wrote:
Show quote
> Thanks, Laurent.....your advice has taken care of the problem.
>
> Regards,
>
> Arpan
>
> Laurent Bugnion wrote:
> > Hi,
> >
> > Arpan wrote:
> >
> > <snip>
> >
> > > The above code successfully gets compiled into a DLL & the ASPX page
> > > that imports the above namespace executes without any errors as well
> > > but Visual Web Developer 2005 Express Edition underlines the word
> > > "UserDetails" at all the places within the GetDetails function
> > > (including the function declaration line) indicating a compiler error
> > > that says:
> > >
> > > 'UserDetails' is ambiguous in the namespace 'Users'.
> > >
> > > What's causing this compiler error in VWD 2005?
> > >
> > > Thanks,
> > >
> > > Arpan
> >
> > Please allow me to write the example in C#, as I am not fluent in VB.NET
> > and wouldn't want to write wrong code.
> >
> > "Ambiguous" in that case means that a class with the name "UserDetails"
> > is defined in more than one namespace.
> >
> > The unique name for a class is formed using the full namespace hierarchy
> > and the class name.
> >
> > example: System.Web.UI.Control or System.Windows.Forms.Control
> >
> > However, the compiler allows implicit reference to classes using their
> > name only. This might cause a problem if you do this:
> >
> > using System.Web.UI; // Corresponds to VB Import
> > using System.Windows.Forms;
> >
> >
> > and you then try to use the Control class. In that case, the compiler is
> > not sure which "Control" you mean, and will create this warning. In
> > these cases, it's best to use the full name to reference the class, for
> > example:
> >
> > System.Web.UI.Control myControl = new System.Web.UI.Control();
> >
> > HTH,
> > Laurent
> > --
> > Laurent Bugnion, GalaSoft
> > Software engineering: http://www.galasoft-LB.ch
> > Private/Malaysia: http://mypage.bluewin.ch/lbugnion
> > Support children in Calcutta: http://www.calcutta-espoir.ch

AddThis Social Bookmark Button