DapperLib / DapperLib/Dapper

GetColumnHash throws: Object reference not set to an instance of an object.

Open
#1,760 1 comment 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

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

  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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.