Repository navigation
Closed
Labels
Description
PostgreSQL SMALLINT[] mapping fails in Dapper 2.1.86 but works in Dapper 2.1.79.
Environment
- .NET 10
- PostgreSQL
- Npgsql
- Dapper 2.1.86
Database
CREATE TABLE auto_numbers
(
item_name TEXT NOT NULL,
auto_column_name TEXT NOT NULL,
separator_positions SMALLINT[] NOT NULL DEFAULT ARRAY[]::SMALLINT[],
PRIMARY KEY (item_name, auto_column_name)
);Example value:
INSERT INTO auto_numbers
(item_name, auto_column_name, separator_positions)
VALUES
('queue_visits', 'token_no', ARRAY[1]::SMALLINT[]);Model
public sealed record AutoNumberRequest
{
public required string ItemName { get; init; }
public required string AutoColumnName { get; init; }
public required IReadOnlyList<short> SeparatorPositions { get; init; } = [];
}Query
const string sql = """
SELECT
item_name "ItemName",
auto_column_name "AutoColumnName",
separator_positions "SeparatorPositions"
FROM auto_numbers
WHERE item_name = @ItemName
AND auto_column_name = @AutoColumnName
""";
var result = await connection.QuerySingleAsync<AutoNumberRequest>(
sql,
new
{
ItemName = "queue_visits",
AutoColumnName = "token_no"
});Error with Dapper 2.1.86
System.Data.DataException:
Error parsing column 2 (SeparatorPositions=System.Int16[] - Int16[])
System.InvalidCastException:
Object must implement IConvertible.
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
...
Npgsql returns the PostgreSQL SMALLINT[] value as System.Int16[].
Version comparison
With Dapper 2.1.79:
<PackageReference Include="Dapper" Version="[2.1.79]" />the same query and model work correctly.
With Dapper 2.1.86:
<PackageReference Include="Dapper" Version="[2.1.86]" />the query fails with the exception above.
I also tested changing the property from:
IReadOnlyList<short>to:
short[]and short[] also fails with Dapper 2.1.86.
No other application or database changes were made between the tests.
This appears to be a regression in Dapper 2.1.86 when reading PostgreSQL SMALLINT[] values through Npgsql.
Dapper 2.1.79 continues to work correctly with the same PostgreSQL database, Npgsql setup, query, and model.
Reacted by Jorge Paravicini, Wilson Kutegeka, Leandro M. Medeiros, Adrian Cockburn and zotov-y-tg
Activity
fix: Regression - Broken mapping of numeric arrays in Postgres (Dappe…
fix: Regression - Broken mapping of numeric arrays in Postgres (Dappe…
fix: Regression - Broken mapping of numeric arrays in Postgres (Dappe…
trivial(app): read end-user context system labels as int[] (#4450)
zotov-y-tg commentedon Nov 12, 2026
We hit the same regression in production after upgrading Dapper from 2.0.123 to 2.1.89. PostgreSQL
integer[]columns mapped toIReadOnlyCollection<int>properties now throw:Setup: .NET 10, Npgsql 9.0.5. Bisected: 2.1.79 works; 2.1.86 and 2.1.89 fail. We have pinned 2.1.79 for now.
#2239 and #2241 both fix this. Could one of them be merged and released?
mgravell commentedon Nov 20, 2026
Fixed by #2271, merged to main. The fix restores the runtime-checked cast for array columns into interface members, and covers both Npgsql
GetFieldTypeshapes: the concrete array type (Npgsql 9.0.0–9.0.4) andtypeof(Array)(Npgsql 7, 8 and 10) — the latter is what the production reports here were hitting, and is now pinned by tests that run in CI against real PostgreSQL under Npgsql 10. This will ship in the next release; the 2.1.79 pin can be lifted then.Fix 2.1.86 unbox-gate regressions: array columns to interface members…