Skip to content

Improve InvalidCastException message for MySqlDataReader.GetX() #1135

Open
@bgrainger

Description

@bgrainger

From PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#1571 (comment)

If MySqlDataReader.GetX() is called for the wrong data type, or when the underlying data is NULL, it will throw InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'. or InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'..

It's suggested that the column name (if GetX(string) is called) or ordinal number (for GetX(int)) be added to the exception message to help novice users diagnose the issue. Note that any implementation should be exceedingly careful to not regress performance: GetX is called successfully millions of times per day making the (rare) failure have a better message is not worth making the common success case slower.

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