title: Dapper - how to work with dynamic objects
body: <p>I'm using Dapper to query from SQL and have a dynamic query as such:</p>
  
  <pre><code>var returns = conn.Query(dynamicQuery);
  </code></pre>
  
  <p>When I then cycle through the results, I would like to find out what the type of date I am handling is so I tried doing the following:</p>
  
  <pre><code>foreach (var result in results)
  {
      MessageBox.Show(result.GetType().ToString());
  }
  </code></pre>
  
  <p>But it always fails on the <code>MessageBox</code> with the error <code>Cannot perform runtime binding on a null reference</code>.</p>
  
  <p>If I use this instead:</p>
  
  <pre><code>var returns = conn.Query&lt;object&gt;(dynamicQuery);
  </code></pre>
  
  <p>Then the command works, but it gives me a <code>Dapper.SqlMapper+DapperRow</code> object type.</p>
  
  <p>How can I find the type of a <code>dynamic</code> variable?</p>