asp.netvb.net

Error BC30561 - 'Strings' is ambiguous, 'Microsoft.VisualBasic, System.Linq, System.Web.UI.WebControls, System.Linq, System.Web.UI.WebControls'


I am trying to integrate MS Identity into my website project.

Everything worked fine but I had 2 databases (2 x .mdf files), I wasn't happy with having two files and wanted to only use 1 sql database.

So I began changing everything so as to end up with only one file. Seemed like a straight forward thing...

PROBLEM The method which loads an account profile from the sql database started to give a strange error.

An error occurred whilst trying to load the specified account record.Conversion from string "UserNameHere" to type 'Double' is not valid.

The sql field type is char(30) it is NOT double, after making some changes the error message changed to the one in the code block at the top of this question.

Original code:

Strings.Trim(_sxAdapter.GetValue(_sxAdapter.GetOrdinal("dbUsername")))

error BC30561: 'Strings' is ambiguous, imported from the namespaces or types 'Microsoft.VisualBasic, System.Linq, System.Web.UI.WebControls, System.Linq, System.Web.UI.WebControls'.

As far as I can see, the issue is happening via sql, not through the code. I feel that when sql is using the sqlreader, it is trying to convert the string-field to a double.

And then making the changes I made, then flag what could be seen as the CAUSE of the issue, the ambiguity of having the same method/element names.

When I searched the project using the object browser for TRIM This is what I saw.. BC30561.jpg

I cannot seem to resolve this error.

I added Option Explicit and Option Strict to the class modules I resolved all the errors caused by the option explicit/option strict statements being added.

I also partially qualified the dimmed variables in the dim statements and in the parameters of each and every method.

'REM - Original code
Strings.Trim(_sxAdapter.GetValue(_sxAdapter.GetOrdinal("dbUsername")))  error BC30561: 'Strings' is ambiguous, imported from the namespaces or types 'Microsoft.VisualBasic, System.Linq, System.Web.UI.WebControls, System.Linq, System.Web.UI.WebControls'.   

'REM - Next attempt code
'REM - Explicitly declare all conversions (cint/cbyte/clng etc)
Strings.Trim(CStr(_sxAdapter.GetValue(_sxAdapter.GetOrdinal("dbUsername"))))    error BC30561: 'Strings' is ambiguous, imported from the namespaces or types 'Microsoft.VisualBasic, System.Linq, System.Web.UI.WebControls, System.Linq, System.Web.UI.WebControls'.   

I thought I'd post it here before attempting to fully qualify all my dim statements with "GLOBAL.xxxx"

Question What is the textbook / recommended method to resolve this issue?

  1. Should I fully qualify all the dimmed variables with "global."?
  2. Should I use import statements? (Although the issue seems to be related to the imported namespaces/namespace-elements in the first place.
  3. Something else?

Thank you in advance for any help.


Solution

  • As suggested in the comments, you really shouldn't be using that method in the first place. It's basically a holdover from VB6. If you're using .NET, use .NET, i.e. call the Trim method of the String object you want to trim, e.g. instead of this:

    Dim s2 As String = Trim(s1)
    

    do this:

    Dim s2 As String = s1.Trim()
    

    To do that, you need an actual String reference though, where your code produces an Object reference. Rather than GetValue, you should be calling GetString if you expect to get a String, which will actually provide a String reference. If you must start with an Object reference though, you should cast that as type String, using CStr or DirectCast.

    Having said all that, you should understand what the actual error message is telling you in the first place and how to address that type of error in general. You're being told that the type Strings is ambiguous, which means that you have already imported multiple namespaces that all include a type with that name. In that case, if you want to use the type from a specific namespace then all you have to do is actually tell the compiler that. Instead of just using Strings and expecting the compiler to work it out, use Microsoft.VisualBasic.Strings and then there can be no confusion because there's only one type with that name.