Bug #106244 MySqlDataReader.GetFieldValue<Stream> throws InvalidCastException
Submitted: 22 Jan 6:07 Modified: 27 Jan 16:34
Reporter: Bradley Grainger (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:8.0.28 OS:Windows
Assigned to: CPU Architecture:Any

[22 Jan 6:07] Bradley Grainger
Description:
Since bug #93374 was fixed, MySqlDataReader.GetStream now works to return a Stream for a BINARY column. 

My expectation is that GetFieldValue<Stream> would also work, but it does not; instead, it throws InvalidCastException: Unable to cast object of type 'System.Byte[]' to type 'System.IO.Stream'.

How to repeat:
Execute the following SQL:

create table blobs(data mediumblob);
insert into blobs(data) values(X'00112233');

Run the following C#:

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

using var command = new MySqlCommand("select data from blobs", connection);
using var reader = command.ExecuteReader();
reader.Read();
reader.GetStream(0); // works
reader.GetFieldValue<Stream>(0); // throws InvalidCastException
[22 Jan 7:43] MySQL Verification Team
Hello Bradley,

Thank you for the report and test case.

regards,
Umesh
[27 Jan 16:34] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 8.0.29 release, and here's the proposed changelog entry from the documentation team:

The MySqlDataReader.GetFieldValue<T> method returned an exception for calls
attempting to retrieve the value of a BINARY column.

Thank you for the bug report.