#1896·Dapper

System.IndexOutOfRangeException inside GetDapperRowDeserializer method

Author: BazistCreated Apr 21, 2023Updated Aug 7, 2026

Hi, We faced with "Index was outside the bounds of the array." exception inside Dapper library. Unfortunately, we don't have many details for reproducing step-by-step, it was reproduced only once on our azure prod environment (so far). Below what we extracted in logs:

Version: Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null

Stack Trace:

0
{"assembly":"Microsoft.Data.SqlClient, Version=3.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5","method":"Microsoft.Data.SqlClient.SqlDataReader.CheckDataIsReady","level":0,"line":0}
1
{"assembly":"Microsoft.Data.SqlClient, Version=3.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5","method":"Microsoft.Data.SqlClient.SqlDataReader.GetValueInternal","level":1,"line":0}
2
{"assembly":"Microsoft.Data.SqlClient, Version=3.0.0.0, Culture=neutral, PublicKeyToken=23ec7fc2d6eaa4a5","method":"Microsoft.Data.SqlClient.SqlDataReader.GetValue","level":2,"line":0}
3
{"assembly":"Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Dapper.SqlMapper+<>c__DisplayClass171_0.<GetDapperRowDeserializer>b__0","level":3**,"line":1909,"fileName":"/_/Dapper/SqlMapper.cs**"}
4
{"assembly":"Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Dapper.SqlMapper+GridReader+<ReadDeferred>d__52`1.MoveNext","level":4,"line":360,"fileName":"/_/Dapper/SqlMapper.GridReader.cs"}
5
{"assembly":"System.Private.CoreLib, Version=6.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e","method":"System.Collections.Generic.List`1..ctor","level":5,"line":0}
6
{"assembly":"System.Linq, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a","method":"System.Linq.Enumerable.ToList","level":6,"line":0}
7
{"assembly":"Dapper, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null","method":"Dapper.SqlMapper+GridReader.ReadImpl","level":7,"line":164,"fileName":"/_/Dapper/SqlMapper.GridReader.cs"}

С# code

using (SqlMapper.GridReader grid = await conn.QueryMultipleAsync(
                                                            sql: MyProcName,
                                                            param: parameters,
                                                            transaction: tran,
                                                            commandType: CommandType.StoredProcedure))
{
  var expectedResultSetCount = 2;
  var results = new List<IEnumerable<dynamic>>();

  for (int i = 0; i < expectedResultSetCount; i++)
  {
     results.Add(grid.Read<dynamic>());
  }
}

Error raised in strange place, when reader.FieldCount != real amount of columns in reader. File: https://github.com/DapperLib/Dapper/blob/main/Dapper/SqlMapper.cs Line: 1909

Can you please confirm if there is any chance to fix this?