title: Compiling a .Net Core Console App with CoreRT and Dapper
body: <p>I'm attempting to compile my code (a .net core console application) into a native .exe for win-x64 using <a href="https://github.com/dotnet/corert" rel="nofollow noreferrer">CoreRT</a>.  I was able to follow the documentation right up until the section having to do with reflection and using an rd.xml file, which is where I am currently stuck.</p>
  
  <p>My project uses <a href="https://github.com/StackExchange/Dapper" rel="nofollow noreferrer">Dapper</a> as the ORM, which relies on reflection to bind objects from my database.  I only have 2 different types that I am binding, so my assumption is that I need to include these types in the rd.xml.</p>
  
  <p>Right now, when I try to run <code>dotnet publish -r win-x64 -c release</code> from the .net core cli, it finishes successfully, however at runtime, my compiled .exe throws an exception with the following snippet:</p>
  
  <blockquote>
    <p>---> (Inner Exception #0) System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the
    InnerException's StackTrace property. --->
    EETypeRva:0x01202268(System.Reflection.MissingRuntimeArtifactException):
    This object cannot be invoked because it was metadata-enabled for
    browsing only:
    'Dapper.SqlMapper.TypeHandlerCache&lt;System.Data.DataTable&gt;.SetHandler(Dapper.SqlMapper.ITypeHandler)'
    For more information, please visit 
    <a href="http://go.microsoft.com/fwlink/?LinkID=616867" rel="nofollow noreferrer">http://go.microsoft.com/fwlink/?LinkID=616867</a></p>
  </blockquote>
  
  <p>My rd.xml file looks like this:</p>
  
  <pre><code>&lt;Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata"&gt;
    &lt;Application&gt;
          &lt;Type Name="Dapper.SqlMapper.TypeHandlerCache{System.Data.DataTable}"&gt;
            &lt;MethodInstantiation Name="SetHandler" Arguments="Dapper.SqlMapper.ITypeHandler" Dynamic="Required" /&gt;
        &lt;/Type&gt;
    &lt;/Application&gt;
  &lt;/Directives&gt;
  </code></pre>
  
  <p>I assume I need to include references to my models here which would be <code>Foo</code> and <code>Bar</code>, but the error getting thrown refers to Dapper specifically.</p>
  
  <p>The rd.xml file is inside of my project directory, and is referenced in the MyProject.csproj like so:</p>
  
  <p><code>&lt;ItemGroup&gt;
      &lt;EmbeddedResource Include="rd.xml" /&gt;
    &lt;/ItemGroup&gt;</code></p>
  
  <p>I'm wondering if this problem is due to my structure (perhaps the rd.xml should be referenced in a different way), or due to the content of my rd.xml file.  Has anyone dealt with this, or used CoreRT on a project that uses Dapper?</p>