So, I'm trying to use Dapper.net, and I like it. I don't like it when I try to embed objects in a batch download and get the following error:
Invalid type owner for DynamicMethod.
in System.Reflection.Emit.DynamicMethod.Init (string name, MethodAttributes attributes, CallingConventions callConvention, type returnType, type [] signature, type owner, module m, logical skipVisibility, Boolean transparentMethod, StackCrawlMark & stackMark) in System.Reflection. .DynamicMethod..ctor (string name, type returnType, Type [] parameterTypes, Type owner, Boolean skipVisibility) in Dapper.SqlMapper.CreateParamInfoGenerator (Identity identity, Boolean checkForDuplicates, Boolean removeUnused, IList 1 literals) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 3033 at Dapper.SqlMapper.GetCacheInfo(Identity identity, Object exampleParameters, Boolean addToCache) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 2138 at Dapper.SqlMapper.<QueryImpl>d__61 1.MoveNext () in D: \ Dev \ dapper-dot-net \ Dapper NET40 \ SqlMapper.cs: line 1578 on System.Collections.Generic.List 1..ctor(IEnumerable 1 glitch nik)
in System.Linq.Enumerable.ToList [TSource] (IEnumerable 1 source) at Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable 1 commandTimeout, Nullable 1 commandType) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1479 at Dapper.SqlMapper.Query(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Boolean buffered, Nullable 1 commandTimeout, Nullable 1 commandType) in D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1418 at NinjaEvaluation.Data.Database.DapperWrapper.<>c__DisplayClass4 1.b__3 (SqlConnection sqlConnection, transaction SqlTransaction) in C: \ Projects \ Inhouse \ ninjaevaluation \ NinjaEvaluation \ NinjaEvaluation.Data \ Database \ DapperWrapper.cs: line 52 in NinjaEvaluation.Data.Database.DapperWrapper.Invoke (Action`2 action) in C: \ Projects \ Inhouse \ ninjaevaluation \ NinjaEvaluation \ NinjaEvaluation.Data \ Database \ DapperWrapper.cs: line 68
This happens in a completely normal situation when I run my query as follows:
string sql = @" INSERT INTO XXX (XXXId, AnotherId, ThirdId, Value, Comment) VALUES (@XXXId, @AnotherId, @ThirdId, @Value, @Comment)"; var parameters = command .MyModels .Select(model => new { XXXId= model.XXXId, AnotherId= model.AnotherId, ThirdId= model.ThirdId, Value = model.Value, Comment = model.Comment }) .ToArray();
...
sqlConnection.Query(sql, parameters, commandType: commandType, transaction: transaction)
I found the following SO thread started by someone with the same problem, but the problem there seemed to be in the .NET version (3.5), but I am running .NET 4.5 and I cannot figure out what the problem is.
Any suggestions?