While using Dapper to call a stored procedure, I'm receiving the following error:
Procedure or function has too many arguments specified
I'm using DynamicParameters to add a list of simple parameters to the query.
The parameter code looks like this:
var parameters = new DynamicParameters();
parameters.Add(p.Name, p.Value, direction: p.Mode);
The query code looks like this:
var result = _connection.Query<T>(
string.Format("{0}.{1}", request.SchemaName, request.StoredProcedureName),
parameters,
commandType: CommandType.StoredProcedure,
transaction: _transaction);
The executing sql in the profiler shows as following:
exec dbo.storedProcedureName @ParameterNames1=N'ParameterName',@ParameterNames2=N'ParameterName',@RemoveUnused=1
@ParameterNames1 is not at all how the parameter is called. Actually, the names are being passed in as the values (N'ParameterName'). The @RemoveUnused parameter seems completely random to me, as it does not occur in the calling code at all.
The full code for this can be found here: GitHub project at lines 61 and 228.
Edit: I've found that the issue is caused by calling the same procedure twice, with different result sets. So the first time I'm calling it with Query, the second time with Query. Why Dapper is having trouble with this scenario is still a mystery.