469,117 Members | 1,338 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,117 developers. It's quick & easy.

Ambiguous Name In Mamespace?

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

Sep 4 '06 #1
3 1618
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
Sep 5 '06 #2
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
Sep 5 '06 #3
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:
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
Sep 5 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by xuatla | last post: by
1 post views Thread by rn5a | last post: by
9 posts views Thread by neildferguson | last post: by
12 posts views Thread by Nathan Sokalski | last post: by
reply views Thread by Ioannis Vranos | last post: by
11 posts views Thread by =?Utf-8?B?SmVycnkgQw==?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by kglaser89 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.