GetColumnHash throws: Object reference not set to an instance of an object.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
We are experiencing sporadic errors with the following code. We have not been able to reproduce it, but it occurs roughly once a day.
Error Message
System.NullReferenceException: Object reference not set to an instance of an object.
at Dapper.SqlMapper.GetColumnHash(IDataReader reader, Int32 startBound, Int32 length) in //Dapper/SqlMapper.cs:line 38
at Dapper.SqlMapper.QueryAsync[T](IDbConnection cnn, Type effectiveType, CommandDefinition command) in //Dapper/SqlMapper.Async.cs:line 420
Code
var categories = new Dictionary<Guid, Category>();
const string sql = @"
WITH CategoryList AS
(
SELECT ch.Id, ch.Name, ch.ParentId
FROM [Category] ch
WHERE Id IN @ids
UNION ALL
SELECT p.Id, p.Name, p.ParentId
FROM [Category] p
INNER JOIN CategoryList cl ON p.Id = cl.ParentId
)
SELECT DISTINCT Id, Name, ParentId FROM CategoryList";
foreach (var ids in categoriesIds.Batch(500))
{
var result = await sqlClient.QueryAsync<Category>(sql, new { ids });
foreach (var category in result)
{
categories[category.Id] = category.MapToReadModel();
}
}
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
Inspect Dapper/SqlMapper.cs at GetColumnHash and Dapper/SqlMapper.Async.cs at QueryAsync, using the supplied NullReferenceException stack trace as the entry point. Determine which reader metadata can be null during the query path and verify the behavior with a reproducible case or regression test; done means the intermittent exception is explained and the relevant query path is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100