Dapper
Dapper copied to clipboard
GetColumnHash throws: Object reference not set to an instance of an object.
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();
}
}
Confirm. I receive the same exception periodically