System.InvalidCastException - Dapper 1.50.4
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.


Here is the class:

Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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