Repository navigation
Preserve Size set by type handlers for string parameters - #2221
Merged
mgravell merged 1 commit intoNov 20, 2026
Merged
Conversation
When an anonymous object parameter goes through the IL generator path, the generated code set the parameter Size after invoking the registered type handler's SetValue, overwriting whatever Size the handler had configured (typically resetting it to 4000 or -1). Move the string Size emission into the non-handler branch so the handler owns the parameter configuration, matching what DynamicParameters already does. Fixes DapperLib#2141 Co-authored-by: FirmamentalSpring <287222957+FirmaSpring@users.noreply.github.com>
Member
|
Verified and merged (via a merge commit — the test file had drifted since August, so I rebased your test onto the current one during the merge). Right diagnosis, right fix: the Size block now defers to whatever a handler set. This resolves #2141. Thanks! |
This was referenced Nov 20, 2026
Merged
mvmorten
added a commit
to mvmorten/dashboard-starter
that referenced
this pull request
Nov 23, 2026
Updated [Dapper](https://github.com/DapperLib/Dapper) from 2.1.89 to 2.1.100. <details> <summary>Release notes</summary> _Sourced from [Dapper's releases](https://github.com/DapperLib/Dapper/releases)._ ## 2.1.100 ## What's Changed * Fix 2.1.86 unbox-gate regressions: array columns to interface members, sql_variant to primitives by @mgravell in DapperLib/Dapper#2271 * Fix command disposal, parameter callbacks, handler-cache staleness, static properties, and type-map races by @mgravell in DapperLib/Dapper#2272 * Fix deserializer cache race by @jnm2 in DapperLib/Dapper#2219 * Fix cache corruption due to CollectCacheGarbage call during GridReader/Async queries by @aklein53 in DapperLib/Dapper#2218 * Fix false cache hit accounting on initial MultiMapAsync execution by @Nacl-HCl in DapperLib/Dapper#2242 * Fixes QueryMultiple corrupting a later Query<T>'s DynamicParameters -- fixes #243, #2091 by @NadeemAfana in DapperLib/Dapper#2214 * Don't cancel the command after QueryUnbufferedAsync completes normally by @aaronwilliams-tesouro in DapperLib/Dapper#2245 * Preserve Size set by type handlers for string parameters by @JiuYue0820 in DapperLib/Dapper#2221 * Fix MultiMapAsync disposing the reader before unbuffered results are enumerated by @jinseojang0903 in DapperLib/Dapper#2229 * Stop boxing values read via GetFieldValue<T> for the error message by @Giorgi in DapperLib/Dapper#2265 * Fix list initializer in bulk Execute README example by @dajiaohuang in DapperLib/Dapper#2243 ## New Contributors * @aklein53 made their first contribution in DapperLib/Dapper#2218 * @Nacl-HCl made their first contribution in DapperLib/Dapper#2242 * @NadeemAfana made their first contribution in DapperLib/Dapper#2214 * @aaronwilliams-tesouro made their first contribution in DapperLib/Dapper#2245 * @JiuYue0820 made their first contribution in DapperLib/Dapper#2221 * @jinseojang0903 made their first contribution in DapperLib/Dapper#2229 * @dajiaohuang made their first contribution in DapperLib/Dapper#2243 **Full Changelog**: DapperLib/Dapper@2.1.89...2.1.100 Commits viewable in [compare view](DapperLib/Dapper@2.1.89...2.1.100). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore <dependency name> major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore <dependency name> minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore <dependency name>` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore <dependency name>` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore <dependency name> <ignore condition>` will remove the ignore condition of the specified dependency and ignore conditions </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Michael Mortensen <mvmorten@users.noreply.github.com>
This was referenced Nov 23, 2026
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a
TypeHandleris registered forstringand a query is executed with an anonymous object parameter (the IL generator path inCreateParamInfoGenerator), the generated code invokes the handler'sSetValueand then unconditionally sets the parameter'sSizebased on the string length heuristics (DbString.DefaultLength/-1), overwriting whateverSizethe handler configured.Reported in #2141. The
DynamicParameterspath already leaves the Size to the handler; only the IL path diverges.Reproduction
Fix
Move the string
Sizeemission into thehandler is nullbranch, so when a type handler is registered it fully owns parameter configuration, consistent with theDynamicParametersbehavior.Testing
Added
TypeHandlerSetValue_StringParameterSizeIsNotOverwritten_Issue2141toSqliteTypeHandlerTests(in-memory SQLite, no external database required). Verified it fails on current main and passes with this change; the existingSqliteTypeHandlerTestssuite passes.Fixes #2141