title: Dapper throws "Invalid type owner for DynamicMethod."
body: <p>So I'm trying to use Dapper.net and I'm liking it. What I'm not liking is when I try to batch-insert entities and I get the following error thrown:</p>
  
  <p><strong>Invalid type owner for DynamicMethod.</strong></p>
  
  <blockquote>
    <p>at System.Reflection.Emit.DynamicMethod.Init(String name,
    MethodAttributes attributes, CallingConventions callingConvention,
    Type returnType, Type[] signature, Type owner, Module m, Boolean
    skipVisibility, Boolean transparentMethod, StackCrawlMark&amp; stackMark) 
    at System.Reflection.Emit.DynamicMethod..ctor(String name, Type
    returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility)
    at Dapper.SqlMapper.CreateParamInfoGenerator(Identity identity,
    Boolean checkForDuplicates, Boolean removeUnused, IList<code>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.&lt;QueryImpl&gt;d__61</code>1.MoveNext() in
    D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1578    at
    System.Collections.Generic.List<code>1..ctor(IEnumerable</code>1 collection)<br>
    at System.Linq.Enumerable.ToList[TSource](IEnumerable<code>1 source)    at
    Dapper.SqlMapper.Query[T](IDbConnection cnn, String sql, Object param,
    IDbTransaction transaction, Boolean buffered, Nullable</code>1
    commandTimeout, Nullable<code>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</code>1
    commandTimeout, Nullable<code>1 commandType) in
    D:\Dev\dapper-dot-net\Dapper NET40\SqlMapper.cs:line 1418    at
    NinjaEvaluation.Data.Database.DapperWrapper.&lt;&gt;c__DisplayClass4</code>1.b__3(SqlConnection
    sqlConnection, SqlTransaction transaction) in
    c:\Projects\InHouse\ninjaevaluation\NinjaEvaluation\NinjaEvaluation.Data\Database\DapperWrapper.cs:line
    52    at NinjaEvaluation.Data.Database.DapperWrapper.Invoke(Action`2
    action) in
    c:\Projects\InHouse\ninjaevaluation\NinjaEvaluation\NinjaEvaluation.Data\Database\DapperWrapper.cs:line
    68</p>
  </blockquote>
  
  <p>This happens in a completely normal situation when I run my query like this:</p>
  
  <pre><code>        string sql = @" INSERT INTO XXX
                          (XXXId, AnotherId, ThirdId, Value, Comment)
                          VALUES
                          (@XXXId, @AnotherId, @ThirdId, @Value, @Comment)";
  
          var parameters = command
              .MyModels
              .Select(model =&gt; new
              {
                  XXXId= model.XXXId,
                  AnotherId= model.AnotherId,
                  ThirdId= model.ThirdId,
                  Value = model.Value,
                  Comment = model.Comment
              })
              .ToArray();
  </code></pre>
  
  <p>...</p>
  
  <pre><code>sqlConnection.Query(sql, parameters, commandType: commandType, transaction: transaction)
  </code></pre>
  
  <p>I found <a href="https://stackoverflow.com/questions/8705325/dapper-execute-a-command-multiple-times-and-linq-and-toarray">the following SO-thread</a> started by someone having the same problem BUT the issue there seems to have been the .NET version (3.5) but I'm running .NET 4.5 and I can't figure out what the problem is.</p>
  
  <p>Any suggestions?</p>