Dapper cannot find a constructor that fits the query columns
A parameterless default constructor or one matching signatureShort answer
Dapper looks for a public parameterless constructor first. If your type has none, it needs one constructor whose parameter count, names, order and types equal the query columns. Add a parameterless constructor, or make the select list match the constructor exactly, including column order.
Fix it fast
1Find out which cause you have
Write down the column names and order your SQL returns, then compare them with the constructor parameters of the target type.
SELECT id, name, created_at FROM users LIMIT 1;2Match what you see, then jump to its fix
- 1
The target is a record or a class with one constructor that takes argumentsThe type has parameters only, and the columns do not line up with themFix - 2
Columns like user_id against a parameter named userIdColumn names use underscores and parameters do notFix - 3
Names and order are right, but the database returns another numeric or date type than the parameterConstructor type and column type differFix
- 1
What does the error look like?
A parameterless default constructor or one matching signatureThe error appears when Dapper maps rows into a record or a class whose only constructor takes arguments
Cause 1 of 3
The type has parameters only, and the columns do not line up with them
1Check
In Dapper's DefaultTypeMap source, a constructor is skipped when its parameter count differs from the column count. Parameter names are compared with column names by position, ignoring case, and the types must be compatible.
grep -rn "record \|public .*(.* .*)" --include=*.cs Models/2Fix
Select exactly the columns the constructor takes, in the same order and with the same names. Alias columns when the names differ.
public record User(int Id, string Name);
var users = conn.Query<User>("SELECT id AS Id, name AS Name FROM users");3Verify
The query returns objects instead of throwing.
Console.WriteLine(users.First());Confirmed by raw.githubusercontent.com
Cause 2 of 3
Column names use underscores and parameters do not
1Check
The same source has a static MatchNamesWithUnderscores flag, false by default. When it is true, underscores are ignored in the name comparison.
grep -rn "MatchNamesWithUnderscores" --include=*.cs .2Fix
Turn the flag on once at startup, or alias the columns in SQL.
Dapper.DefaultTypeMap.MatchNamesWithUnderscores = true;3Verify
A query with snake_case columns now maps.
var rows = conn.Query<User>("SELECT user_id, user_name FROM users");Confirmed by raw.githubusercontent.com
Cause 3 of 3
Constructor type and column type differ
1Check
The source accepts a column when its type equals the parameter type (after unwrapping Nullable), or when a type handler, enum or char-from-string rule applies. A decimal column against an int parameter is not accepted.
DESCRIBE users;2Fix
Change the parameter type to the type the database returns, cast in SQL, or register a type handler. A public parameterless constructor is accepted as soon as Dapper reaches it, so adding one is the simplest escape.
public class User
{
public User() { }
public int Id { get; set; }
public string Name { get; set; } = "";
}3Verify
The query returns objects. Check that the properties hold real values, not defaults.
Console.WriteLine(users.First().Name);Confirmed by raw.githubusercontent.com
How do I stop it coming back?
- Name every column in the select list, in the order of the constructor, instead of SELECT *.
- Alias database columns to the property names once, in one place.
- Add a public parameterless constructor to types that Dapper fills.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Databases
.NET Framework app cannot load the Unsafe assembly after a NuGet update
System.IO.FileLoadException
This happens on .NET Framework when one package asks for a different version of the assembly than the one in your bin folder, and no binding redirect joins them.
4 causes, each with a fixDatabases
EF Core logs 'An error occurred using the connection to database' with MySQL
Can't connect to MySQL server on 'host_name' (111)
This EF Core message is only a wrapper.
3 causes, each with a fixDatabases
DbContextOptionsBuilder has no UseMySql method
Cannot find the UseMysql method on DbContextOptions
UseMySql comes from a provider package, not from EF Core itself.
3 causes, each with a fixDatabases
There is already an open DataReader on the MySQL connection
The error appears inside a while (reader.Read()) loop
One MySQL connection runs one operation at a time.
3 causes, each with a fixDatabases
C# INSERT fails with 'Fatal error encountered during command execution'
MySql.Data.MySqlClient.MySqlException: Fatal error encountered during command execution
A fatal error during command execution means the connection broke while the INSERT was in flight.
3 causes, each with a fixDatabases
MySqlException: Timeout expired in a .NET app
MySql.Data.MySqlClient.MySqlException: Timeout expired
Timeout expired means a wait ended before it finished.
3 causes, each with a fix