title: What could cause a Dapper cast to fail?
body: <p>I am using Dapper to execute a very simple query:</p>
  
  <pre><code>const string query =
            "SELECT measurement From Table;";
  return connection.Query&lt;Foo&gt;(query);
  </code></pre>
  
  <p>with <code>foo</code> defined as follows:</p>
  
  <pre><code>public class Foo
  {
      public object measurement { get; set; }
  }
  </code></pre>
  
  <p>It works perfectly. If I inspect the resulting object, <code>Measurement</code> is a <code>double</code>.</p>
  
  <p>However, if I explicitely type <code>Measurement</code> as a <code>double</code>:</p>
  
  <pre><code>public class Foo
  {
      public double measurement { get; set; }
  }
  </code></pre>
  
  <p>Dapper throws an exception:</p>
  
  <blockquote>
    <p>System.Data.DataException: 'Error parsing column 0
    (measurement=4.64518928527832 - Double)'</p>
  </blockquote>
  
  <p>Since typing as object works, it is not too annoying, but I would like to understand what causes this behavior.</p>
  
  <p>Edit: Doing the same thing the old-fashionned way works perfectly fine with <code>measurement</code> typed as a <code>Double</code></p>
  
  <pre><code>using (connection)
              {
                  connection.Open();
                  var cmd = connection.CreateCommand();
                  cmd.CommandText = "SELECT measurement From Table;";
                  Foo foo= new Foo();
                  using (IDataReader reader = cmd.ExecuteReader())
                  {
                      reader.Read();
                      foo.measurement = reader.GetDouble(0);
                  }
              }
  </code></pre>
  
  <p>Edit2: Neither the stack trace</p>
  
  <blockquote>
    <p>Dapper.SqlMapper.ThrowDataException(Exception ex, Int32 index, IDataReader reader, Object value)</p>
  </blockquote>
  
  <p>nor the inner exception</p>
  
  <blockquote>
    <p>System.InvalidCastException / "The specified cast is invalid"</p>
  </blockquote>
  
  <p>are very useful.</p>