Poor error message when using 'DynamicParameter.Output<T>' on property without setter
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
I was playing around with the Output<T>´ method on a DynamicParameters` instance and it took me a crazy amount of time to figure out the problem I was having.
Here is a sample piece of code:
var template = new
{
skipCount = 1,
takeCount = 2,
totalCount = default(long?)
};
var parameters = new DynamicParameters(template)
.Output(template, t => t.totalCount);
This gives me the following exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: meth
at System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, MethodInfo meth)
at Dapper.DynamicParameters.Ouytput[T](T target, Expression1 expression, Nullable1 dbType, Nullable`1 size) in ...
After fiddling around with the problem in different ways, I realized it was because an annonymous object's properties are all read-only, so it was trying to retrieve the setter method on the property and returning null.
I suggest that this particular scenario is better handled to emit a decent error message on Output<T> when the specified property has no setter (like InvalidOperationException).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at DynamicParameters.Output and reproduce the anonymous-object sample from the issue, focusing on the property setter lookup that currently leads to the null-method exception. Done means that using Output with a property lacking a setter produces a clear, intentional error instead of the reflection failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100