Skip to content

Report getter-only properties in output parameter errors - #2279

Merged
mgravell merged 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/output-readonly-property-error
Nov 24, 2026
Merged

mgravell merged 1 commit into
DapperLib:mainfrom
tuncaypeker:fix/output-readonly-property-error

Conversation

@tuncaypeker

Copy link
Copy Markdown
Contributor

Fixes #1148.

Registering an Output expression that targets a getter-only property currently passes a null setter to ILGenerator.Emit, producing ArgumentNullException with the internal parameter name "meth".

Throw InvalidOperationException naming the property and explaining that an output property needs a setter. Keep using GetSetMethod(true) so private setters remain supported. No public signatures or dependencies are added.

Validation:

  • Reproduced on unmodified upstream main at 1880947 on net10.0: anonymous, getter-only, and nested getter-only properties all produce the internal ArgumentNullException. The three regression cases fail; four valid output controls pass.
  • Seven database-free tests cover the three rejection cases and successful callback assignment through public setters, private setters, getter-only intermediate parents with writable final properties, and fields. The controls prepare a disconnected SqlCommand and invoke the parameter callbacks without opening a database connection.
  • The seven new cases plus existing output-expression tests pass on net481, net8.0, and net10.0: 31 passed per framework, with no failures or skips. Existing integration cases use SQL Server 2025 LocalDB with 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.

Nice, tight fix: a readable error instead of the internal ArgumentNullException, and private setters still work. Thanks!

@mgravell
mgravell merged commit 72f7ffa 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.

Poor error message when using 'DynamicParameter.Output<T>' on property without setter

2 participants