XS0121 The call is ambiguous ...MySQL.Data

This forum is meant for questions and discussions about the X# language and tools
Post Reply
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

XS0121 The call is ambiguous ...MySQL.Data

Post by ic2 »

I installed the previous X# and as a result immediately got some new errors. From one I don't understand why my fix didn't change it:

Error XS0121 The call is ambiguous between the following methods or properties: 'MySql.Data.MySqlClient.MySqlDataReader.GetString(string)' and 'System.Data.Common.DbDataReader.GetString(int)'

Code line is:

cValue:=Trim(oSQLrdr:GetString(AFields[ni]))

so I changed

Local oSQLrdr As MySqlDataReader
to
Local oSQLrdr As MySQL.Data.MySQLClient.MySqlDataReader

Why doesn't adding the namespace to the variable definition not solve this error?

Dick
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

XS0121 The call is ambiguous ...MySQL.Data

Post by robert »

Dick,
Most likeliy you are using a VO style array in aFields{}. The values in this array are of type USUAL.
At compile time the type of the contents of the USUAL is know known.
And there are runtime conversions available from USUAL to both Int and String.
So the compiler has no idea which of the two overloads you want to call.
If you know that the array contains strings you can add change the code to GetString( (String) aFields[ni] )
when you know that the array contains numbers then you can change the code to GetString ( (int) aFields[nI] ).

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

XS0121 The call is ambiguous ...MySQL.Data

Post by ic2 »

Hello Robert,

Thanks for the reply, but when I change the line to:

cValue:=Trim(oSQLrdr:GetString(String)(AFields[ni]))
the error changes to:


Error XS0149 Method name expected

This is not explained in the help so I have no idea what to do next.

It used to work in earlier version. Can't I do something that it works without changing the code?

Although I understand that it's probably a good idea to tighten the compiler but it makes me very reluctant to update to a new version if I have to fix all kind of code lines which used to work fine before. I was using the July 2020 version until last week.


Dick
User avatar
robert
Posts: 4225
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

XS0121 The call is ambiguous ...MySQL.Data

Post by robert »

Dick,
The text (String) has to come between the open parenthesis from GetString and aFields:

Code: Select all

cValue:=Trim(oSQLrdr:GetString((String)AFields[ni]))
Or you use a temp variable:

Code: Select all

cValue := AFields[ni]
cValue := Trim(oSQLrdr:GetString(cValue))
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
ic2
Posts: 1798
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

XS0121 The call is ambiguous ...MySQL.Data

Post by ic2 »

Hello Robert,

The 2 step second suggestion compiles fine now and is also a lot more readable; thanks.
Dick
Post Reply