Bug #103390 Can't read CHAR(36) column if MySqlCommand is prepared
Submitted: 20 Apr 19:19 Modified: 28 May 8:14
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Verified Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.24, 8.0.25 OS:Microsoft Windows (10)
Assigned to: CPU Architecture:Other (x64)

[20 Apr 19:19] Bradley Grainger
This bug was introduced in 8.0.22 but may have been obscured by bug #101252 (that occurs in a similar situation); it was also less visible in that release because IgnorePrepare defaulted to true. It's still present in 8.0.24.

When querying a CHAR(36) column, reading a non-NULL value will fail if the MySqlCommand is prepared.

How to repeat:
Create a table and insert a GUID value:

drop table if exists prepared_command_test;
create table prepared_command_test(value char(36));
insert into prepared_command_test(value) values ('3e22b63e-8077-43ab-8cee-17aa1db80861');

Query that table with the following C# code:

using var connection = new MySqlConnection("...");
using var cmd = connection.CreateCommand();
cmd.CommandText = "select value from prepared_command_test";
cmd.Prepare(); // works fine if this line is commented out
using var reader = cmd.ExecuteReader();
while (reader.Read()) // <-- throws here

The program throws an exception:

Unhandled Exception: System.ArgumentOutOfRangeException: Non-negative number required.
Parameter name: count
   at System.Text.UTF8Encoding.GetString(Byte[] bytes, Int32 index, Int32 count)
   at MySql.Data.MySqlClient.NativeDriver.ReadColumnValue(Int32 index, MySqlField field, IMySqlValue valObject)
   at MySql.Data.MySqlClient.ResultSet.ReadColumnData(Boolean outputParms)
   at MySql.Data.MySqlClient.ResultSet.NextRow(CommandBehavior behavior)
   at MySql.Data.MySqlClient.MySqlDataReader.Read()
   at Test.Program.Main(String[] args)
[28 May 8:14] MySQL Verification Team
Hello Bradley,

Thank you for the report and test case.
Verified as described.