Exception: Dapper throws Value cannot be null. Parameter name: con

If you are using Dapper and try to select data into an object and don’t have a default constructor the exception

Value cannot be null.
Parameter name: con

might be thrown.

The stack is:

[ArgumentNullException: Value cannot be null.
Parameter name: con]
   System.Reflection.Emit.DynamicILGenerator.Emit(OpCode opcode, ConstructorInfo con) +9566558
   Dapper.SqlMapper.GetClassDeserializer(IDataReader reader, Int32 startBound, Int32 length, Boolean returnNullIfFirstMissing) in C:\pathtomyproject\SqlMapper.cs:1177
   Dapper.SqlMapper.GetDeserializer(IDataReader reader, Int32 startBound, Int32 length, Boolean returnNullIfFirstMissing) in C:\pathtomyproject\SqlMapper.cs:674
   Dapper.<QueryInternal>d__4`1.MoveNext() in C:\pathtomyproject\SqlMapper.cs:397
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +327
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +58
   Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\pathtomyproject\SqlMapper.cs:348

 

Tags: ,

Leave a Reply