Skip to content

Clear stale column values before deserialization reads - #2276

Merged
mgravell merged 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/column-error-diagnostics
Nov 24, 2026
Merged

mgravell merged 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/column-error-diagnostics

Conversation

@tuncaypeker

Copy link
Copy Markdown
Contributor

Fixes #1323.

When a provider throws while reading a column, the deserializer has already recorded that column's index but may still hold the previous column's value for diagnostics. The resulting DataException names the failing column and shows a value from a different column.

Clear the object diagnostic local before each mapped column is read. A value successfully read from the current column is still retained for conversion or setter errors, including the unboxed GetFieldValue path. This adds no public API or dependencies.

Validation:

  • Reproduced on unmodified upstream main at 1880947 with a provider-independent fake reader: both property mapping and constructor mapping show the previous column's sentinel value in the second column's error. Both regression cases fail; a current-value conversion-error control passes.
  • Five regression cases cover property and constructor read failures, a mixed GetValue/GetFieldValue read failure, and controls retaining the current value on conversion and typed-setter failures.
  • The regression and existing type-mapping tests pass on net10.0: 18 passed.
  • No real MySQL reproduction was performed; the reader fault is simulated directly at the provider API boundary.
  • Selected column-diagnostic, type-mapping, reader, constructor, multi-map, null, type-handler, SQLite, date/time, and enum tests pass on net481 (178), net8.0 (187), and net10.0 (187), with no skips or failures. SQL Server tests use SQL Server 2025 LocalDB and both SqlClient providers.
  • The full repository test suite was not run.
  • Release library build succeeds for net461, netstandard2.0, net8.0, and net10.0 with zero warnings or errors.

@mgravell mgravell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Reporting another column's value in the error is misleading, and can surface data that has nothing to do with the failure. The IL change is minimal, and the tests pin both the provider-read failure and the "current value is still reported" cases. Thanks!

@mgravell
mgravell merged commit f2ad8cc into DapperLib:main Nov 24, 2026
2 checks passed
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.

Error parsing column {index} ({name}={formattedValue}) has wrong formattedValue

2 participants