Skip to content

Fix stale deserializers after adding a type handler - #2247

Closed
alaricd wants to merge 1 commit into
DapperLib:mainfrom
pengdows:fix/issue-885
Closed

alaricd wants to merge 1 commit into
DapperLib:mainfrom
pengdows:fix/issue-885

Conversation

@alaricd

@alaricd alaricd commented Oct 24, 2026

Copy link
Copy Markdown

Fixes #885.

Adding a type handler after a query is cached must invalidate cached deserializers, including deserializers for types that use the handled type as a member.

This adds a fakeDb regression test and purges the query/deserializer caches when handlers change.

@mgravell

Copy link
Copy Markdown
Member

Real long-standing gotcha — deserializers compiled before AddTypeHandler silently ignored the handler forever, and your full-purge reasoning is right (a handled type can be a member of any cached type, so a per-type purge can't work). Adopted in #2272, gated so static-init registrations skip the purge, with a deterministic register-after-compile test on in-repo infrastructure. See #2199 for the note on the test dependency. Thanks!

@mgravell mgravell closed this Nov 20, 2026
mgravell added a commit that referenced this pull request Nov 20, 2026
…tatic properties, and type-map races (#2272)

Five small fixes, each identified by community PRs (credit: alaricd), re-tested
on the repo's existing test infrastructure:

- DbWrappedReader.DisposeAsync now disposes the wrapped command, mirroring the
  sync Dispose path; 'await using' on an ExecuteReaderAsync result previously
  leaked the command (#2185, community PR #2264)
- QueryMultiple / QueryMultipleAsync now pass custom IParameterCallbacks
  implementations to the GridReader, not just DynamicParameters, so OnCompleted
  fires for them (#2179, community PR #2257, extended to the async call site)
- AddTypeHandler purges compiled deserializer caches: a handler registered
  after a deserializer was compiled for a containing type is now honored
  (community PR #2247)
- public static properties on parameter objects are ignored: the emitted IL
  loads the instance before each getter call, which is an invalid program for
  a static getter (community PR #2254)
- AddTypeMap / RemoveTypeMap clone-and-swap now happens under a lock, so
  concurrent registrations cannot lose each other's updates (community PR #2251)

Fixes #2179, fixes #2185
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.

SqlMapper.AddTypeHandler doesnt reset internal deserializer cache

2 participants