Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unhelpful exception message when reading NULL value #1092

Copy link
Copy link
Closed
@bgrainger

Description

@bgrainger
Issue body actions
using var cmd = new MySqlCommand("select null;", connection);
using var reader = cmd.ExecuteReader();
reader.Read();

reader.GetInt32(0); // InvalidCastException: Specified cast is not valid.

reader.GetInt64(0); // InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.Int64'.

// MySql.Data
reader.GetInt32(0); // SqlNullValueException: Data is Null. This method or property cannot be called on Null values.

User at https://stackoverflow.com/q/70132978/23633 was probably not helped by the low-information exception message. Commenters would also probably have been quicker to help him if the GetInt32 message was more like the GetInt64 message.

MySql.Data has a different exception type, which is even more clear; MySqlConnector uses InvalidCastException by design, so it's not necessary to change the exception type but it could have a better message.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.