DapperLib / DapperLib/Dapper

Misleading error message when failing to find constructor.

Open
#1,680 0 comments 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

Consider

var sql = "select [TABLE_CATALOG] as [TableCatalog], [TABLE_SCHEMA] as [TableSchema], [TABLE_NAME] as [TableName], [COLUMN_NAME] as [ColumnName], [IS_NULLABLE] as [IsNullable], [DATA_TYPE] as [DataType], [CHARACTER_MAXIMUM_LENGTH] as [CharacterMaximumLength], [NUMERIC_PRECISION_RADIX] as [NumericPrecisionRadix], [NUMERIC_PRECISION] as [NumericPrecision] from INFORMATION_SCHEMA.COLUMNS";

public record Column(
        string TableCatalog, 
        string TableSchema, 
        string TableName,
        string ColumnName,
        string IsNullable,
        int DataType, // WRONG
        int? CharacterMaximumLength, // CORRECT
        short? NumericPrecisionRadix,
        byte? NumericPrecision);

var x = await connection.QueryAsync<Column>(sql);

Then the error message generated is

A parameterless default constructor or one matching signature (System.String TableCatalog, System.String TableSchema, System.String TableName, System.String ColumnName, System.String IsNullable, System.String DataType, System.Int32 CharacterMaximumLength, System.Int16 NumericPrecisionRadix, System.Byte NumericPrecision) is required for ConsoleApp4.Column materialization

Note that it suggests we need to change the last three fields, but in practice you only need to fix DataType.

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

Reproduce the issue with the shown QueryAsync call and the mismatched DataType constructor parameter. Trace the constructor-matching and materialization error generation, then verify that the message identifies the actual mismatched parameter and that the example has regression coverage.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.