Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix InvalidCastException when reading MySql DateTime #1916

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

0xced
Copy link
Contributor

@0xced 0xced commented Jun 13, 2023

Before this commit, the following exception would be thrown:

System.InvalidCastException
Unable to cast object of type 'MySqlConnector.MySqlDateTime' to type 'System.Nullable`1[System.DateTime]'.
at Deserialize74d21eca-a78e-49dc-b635-d007c613cb51(DbDataReader )

Fixes #295

Before this commit, the following exception would be thrown:
> System.InvalidCastException
> Unable to cast object of type 'MySqlConnector.MySqlDateTime' to type 'System.Nullable`1[System.DateTime]'.
> at Deserialize74d21eca-a78e-49dc-b635-d007c613cb51(DbDataReader )

Fixes DapperLib#295
@@ -3716,7 +3716,7 @@ private static void LoadReaderValueOrBranchToDBNullLabel(ILGenerator il, int ind
{
TypeCode dataTypeCode = Type.GetTypeCode(colType), unboxTypeCode = Type.GetTypeCode(unboxType);
bool hasTypeHandler;
if ((hasTypeHandler = typeHandlers.ContainsKey(unboxType)) || colType == unboxType || dataTypeCode == unboxTypeCode || dataTypeCode == Type.GetTypeCode(nullUnderlyingType))
if ((hasTypeHandler = typeHandlers.ContainsKey(unboxType)) || colType == unboxType || dataTypeCode == (nullUnderlyingType != null ? Type.GetTypeCode(nullUnderlyingType) : unboxTypeCode))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is why I hate writing ref-emit code; what's the impact of this change... "who knows?"

I'll need to read this while very very awake...

@dove
Copy link

dove commented Oct 2, 2023

Will this merge be accepted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reading nullable DateTime fails when the column has a non-null value
3 participants