Ambiguous Name In Mamespace?

A

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
 
L

Laurent Bugnion

Hi,

Arpan wrote:

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
 
A

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top