Skip to content

Fix PostgreSQL array to interface mapping regression (fixes #2231) - #2241

Open
SENESO wants to merge 1 commit into
DapperLib:mainfrom
SENESO:fix/postgres-array-interface-regression
Open

SENESO wants to merge 1 commit into
DapperLib:mainfrom
SENESO:fix/postgres-array-interface-regression

Conversation

@SENESO

@SENESO SENESO commented Oct 8, 2026

Copy link
Copy Markdown

Fixes #2231.

The DateOnly/TimeOnly re-enable (6d48ef6, #2228) added a TypeCode.Object guard to the direct-unbox condition in LoadReaderValueOrBranchToDBNullLabel. That guard also blocks legitimate direct unboxes where both sides report TypeCode.Object but the runtime type satisfies the target — e.g. Npgsql returns SMALLINT[] as short[], and mapping it to IReadOnlyList fell through to Convert.ChangeType, which throws InvalidCastException on arrays.

This adds unboxType.IsAssignableFrom(colType) as a direct-unbox trigger:

  • IReadOnlyList.IsAssignableFrom(short[]) is true → takes the direct unbox path (arrays implement the interface, so Unbox_Any is safe)
  • TimeOnly.IsAssignableFrom(TimeSpan) is false → the original DateOnly/TimeOnly fix stays intact

The check runs once per column at deserializer-build time (cached), so there's no per-row perf cost.

…#2231)

The DateOnly/TimeOnly re-enable (6d48ef6) added a TypeCode.Object guard
that blocks legitimate direct unboxes where both sides report Object but
the runtime type satisfies the target — e.g. short[] to IReadOnlyList<short>.

Adds unboxType.IsAssignableFrom(colType) as a direct-unbox trigger.
IReadOnlyList<short>.IsAssignableFrom(short[]) is true (fix works), while
TimeOnly.IsAssignableFrom(TimeSpan) is false (the original DateOnly/TimeOnly
fix stays intact).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PostgreSQL SMALLINT[] mapping fails in Dapper 2.1.86 but works in 2.1.79

1 participant