System.IndexOutOfRangeException inside GetDapperRowDeserializer method
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
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?
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
Start with Dapper/SqlMapper.cs at line 1909 and follow the GridReader paths in Dapper/SqlMapper.GridReader.cs at lines 360 and 164. Use the supplied QueryMultipleAsync and stored-procedure pattern while investigating the reported FieldCount mismatch with Microsoft.Data.SqlClient. Done means a reproducible failure and a regression test or a documented reason it cannot be handled safely.
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
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 38/100