Closed
Description
Software versions
MySqlConnector version: 2.2.6 or above
Server type: MySQL 5.0 (an old MySQL version, connection.Session.ServerVersion.Version < ServerVersions.RemovesMySqlProcTable)
Describe the bug
Got InvalidCastException in C# when use MySQLCommand (StoredProcedure) to ExecuteReader.
Unable to cast object of type 'System.String' to type 'System.Byte[]'.
The stored procedure has no input/output parameters, simply a select statement
BEGIN
select distinct(name) from tablename WHERE code LIKE 'ABC%';
END
The exception is when CachedProcedure.FillAsync force converting the String to byte[]
line 32: var returnsSqlBytes = (byte[]) reader.GetValue(1);
Exception
at System.Runtime.CompilerServices.CastHelpers.ChkCastAny(Void* toTypeHnd, Object obj)
at MySqlConnector.Core.CachedProcedure.<FillAsync>d__0.MoveNext() in /_/src/MySqlConnector/Core/CachedProcedure.cs:line 31
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at MySqlConnector.MySqlConnection.<GetCachedProcedure>d__88.MoveNext() in /_/src/MySqlConnector/MySqlConnection.cs:line 818
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at MySqlConnector.Core.CommandExecutor.<ExecuteReaderAsync>d__0.MoveNext() in /_/src/MySqlConnector/Core/CommandExecutor.cs:line 33
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.ValueTask`1.get_Result()
at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
at MySqlConnector.MySqlCommand.<ExecuteReaderAsync>d__84.MoveNext() in /_/src/MySqlConnector/MySqlCommand.cs:line 357
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Threading.Tasks.ValueTask`1.get_Result()
at MySqlConnector.MySqlCommand.ExecuteReader() in /_/src/MySqlConnector/MySqlCommand.cs:line 112
Code sample
/* A concise code sample to reproduce the bug */
using (MySqlConnection connection = new MySqlConnection(connectionString))
{
connection.Open();
using (MySqlCommand command = connection.CreateCommand())
{
command.CommandText = "spname";
command.CommandType = System.Data.CommandType.StoredProcedure;
command.ExecuteNonQuery();
}
}
Expected behavior
Should be able to use stored procedure with MySQL 5.0