DapperLib / DapperLib/Dapper

System.InvalidCastException - Dapper 1.50.4

Open
#1,001 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

My team and I have discovered what seems to be a bug in Dapper v1.50.4

Exception thrown: 'System.InvalidCastException' in Dapper.dll
Exception thrown: 'System.Data.DataException' in Dapper.dll

The bug is simple, if a field (INT for example) is created and if the first value inserted into this field is Null and the second value inserted is an INT. The program will crash unless than value is cast to the correct type.

This program has been built to show how to duplicate the issue:
https://github.com/rhfrench/DapperTest

We were also having trouble nullable int values even when the values are cast to the correct type. The first image is the actual error I'm running into. The second image shows the output of the query that is being run. We are using Microsoft.Data.Sqlite 2.0.1.

image

image

Here is the class:
image

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the linked DapperTest reproduction and the reported Dapper v1.50.4 behavior using Microsoft.Data.Sqlite 2.0.1. Compare the null-then-int insert case with nullable-int queries, and consider the issue done when the reproduction no longer throws InvalidCastException or DataException without requiring manual casts.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sqlite
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.