Bug #103259 Connector/NET throws exception in query if field contains a null Guid

Submitted: 8 Apr 2021 22:07 Modified: 9 Apr 2021 12:57
Reporter: Nick Peck Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:8.0.22 OS:Windows
Assigned to: CPU Architecture:Any
Tags: ArgumentOutOfRangeException, Guid

[8 Apr 2021 22:07] Nick Peck
Description:
Recent versions of Connector/NET throw an exception for queries that return a field that contains a null when the data type is System.Guid.  The typical behavior for Connector/NET is to return a System.Guid when the column is created as char(36).  If the field contains a null, Connector/NET normally returns a System.DBNull object.  Since Connector/NET 8.0.22 the result has been an exception.  I believe the problem is entirely in the connector, but so you know I’m testing with MySQL Community Server 5.6.26, InnoDb.  It’s easy to demonstrate the problem.

How to repeat:
Create a table and insert a couple rows:

CREATE TABLE entities (
  id int NOT NULL AUTO_INCREMENT,
  notnullguid char(36) NOT NULL,
  nullguid char(36) DEFAULT NULL,
  PRIMARY KEY (id)
)

insert into entities (notnullguid,nullguid) values ('275d7683-0cc8-44ea-8e64-29872d10fc23','1fcb5dbf-d107-4783-8e9c-e05786e40410');
insert into entities (notnullguid) values ('cf81cf52-9426-43f3-aaa3-33a425646c07');

The table looks like this:

+----+--------------------------------------+--------------------------------------+
| id | notnullguid                          | nullguid                             |
+----+--------------------------------------+--------------------------------------+
| 1  | 275d7683-0cc8-44ea-8e64-29872d10fc23 | 1fcb5dbf-d107-4783-8e9c-e05786e40410 |
| 2  | cf81cf52-9426-43f3-aaa3-33a425646c07 | (null)                               |
+----+--------------------------------------+--------------------------------------+

Now some queries:

select * from entities where id=1  <-- THIS QUERY WORKS
select * from entities where id=2  <-- THIS QUERY FAILS WITH AN EXCEPTION STARTING WITH Connector/NET 8.0.22.

Example code:

MySqlConnection sql_con = new MySqlConnection(connect_str);
sql_con.Open();

MySqlCommand cmd = sql_con.CreateCommand();
cmd.CommandText = "select * from entities where id=2";

MySqlDataReader reader = cmd.ExecuteReader();
reader.Read(); // <-- exception

Exception ToString():

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 MySQLTest.Form1.button1_Click(Object sender, EventArgs e)
[9 Apr 2021 4:00] Bradley Grainger
This sounds like a duplicate of bug #101252.
[9 Apr 2021 12:57] MySQL Verification Team
Hello Nick Peck,

Thank you for the bug report.
Imho this is duplicate of Bug #101252, please see Bug #101252.

Regards,
Ashwini Patil

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.055 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.