What causes “extension methods cannot be dynamically dispatched” here?

So, can somebody please help me understand why leveraging the same overload inside of those other methods is failing with that error?

Precisely because you’re using a dynamic value (param) as one of the arguments. That means it will use dynamic dispatch… but dynamic dispatch isn’t supported for extension methods.

The solution is simple though: just call the static method directly:

return SqlMapper.Query(_connection, sql, param, transaction,
                       buffered, commandTimeout, commandType);

(That’s assuming you really need param to be of type dynamic, of course… as noted in comments, you may well be fine to just change it to object.)

Leave a Comment