Solution for "Invalid return type" from Dapper.Contrib when inserting row

This is another one of those embarrassing moments. I just had this issue for quite some time and I could not figure out what I was doing wrong. I almost ended up with the conclusion that there had to be something wrong with dapper (it had to be!). As always, it was the programmer not the code that was at fault.

What I had written was something similar to the below. A simple insert for an object. Could it be simpler? Even the fewest lines of code can have errors. The error was in the generic parameter.

var person = new Person{
   Name = "Peter"
};
connection.Insert<Person>(person);

I did not have to specify the type Person. This was actually used for the return type not the type to be inserted. When specified, dapper will try and map to this type. Hence the unexpected message Invalid return type. Below is an example of how it should be done.

var person = new Person{
   Name = "Peter"
};
connection.Insert(person); // NO generic type!

I hope this helps someone out there - feel free to leave a comment if it did!