Bug #101252 Can't query CHAR(36) column containing NULL
Submitted: 20 Oct 20:09 Modified: 21 Oct 5:52
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.22 OS:Microsoft Windows (10)
Assigned to: CPU Architecture:Any
Tags: regression

[20 Oct 20:09] Bradley Grainger
Description:
The column type CHAR(36) is used to represent a GUID in MySQL Server (and MySqlDataReader.GetValue will return a System.Guid value from that column).

Starting in 8.0.22, querying a CHAR(36) column containing NULL values will throw an ArgumentOutOfRangeException.

ArgumentOutOfRangeException: Non-negative number required. (Parameter 'count') 
StackTrace:
   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() 

How to repeat:
Run the following C# code:

using var connection = new MySqlConnection("...");
connection.Open();

using var command = new MySqlCommand(@"drop table if exists guid_test;
create table guid_test(value char(36));
insert into guid_test(value) values(null);", connection);
command.ExecuteNonQuery();

command.CommandText = "select value from guid_test;";
using var reader = command.ExecuteReader();
while (reader.Read()) // <-- exception thrown here
{
	Console.WriteLine(reader.IsDBNull(0)); // expected True
}

Suggested fix:
Test for 'length != -1' here: https://github.com/mysql/mysql-connector-net/commit/c8b7779b9f98f6985600483a5331d951f40127...
[21 Oct 5:52] MySQL Verification Team
Hello Bradley,

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

regards,
Umesh
[19 Nov 16:47] Kevin Hoang
Hi,
When will this bug be fixed? I'm getting the same issue when updating to MySql.Data version 8.0.22.

Regards,
Kevin