DapperLib / DapperLib/Dapper

IDataReader.GetRowParser<string>() throws exception

Open
#1,822 3 comments 2 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

Using .NET Core 6
Dapper v 2.0.123

using Dapper;
using Microsoft.Data.SqlClient;

using var connection = new SqlConnection("Server=localhost;Database=Test;Integrated Security=True;Encrypt=False");

var reader = connection.ExecuteReader("select 'test' as col");
var rowParser = reader.GetRowParser<string>();

reader.Read();
string result = rowParser(reader);

Throws exception:

System.InvalidCastException: 'Unable to cast object of type 'System.Func`2[System.Data.IDataReader,System.Object]' to type 'System.Func`2[System.Data.IDataReader,System.String]'.'
reader.GetRowParser<object>(typeof(string))

works, but then extra unboxing is needed: string result = (string)rowParser(reader)

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

Start with the IDataReader.GetRowParser() call shown in the reproduction and compare it with the working GetRowParser(typeof(string)) overload. Verify the behavior against the provided SQL reader example; done means the generic string parser can be invoked without an InvalidCastException or extra unboxing.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.