I'm attempting to compile my code (a .net core console application) into a native .exe for win-x64 using CoreRT. 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.
My project uses Dapper 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.
Right now, when I try to run dotnet publish -r win-x64 -c release from the .net core cli, it finishes successfully, however at runtime, my compiled .exe throws an exception with the following snippet:
---> (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<System.Data.DataTable>.SetHandler(Dapper.SqlMapper.ITypeHandler)' For more information, please visit http://go.microsoft.com/fwlink/?LinkID=616867
My rd.xml file looks like this:
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
<Application>
<Type Name="Dapper.SqlMapper.TypeHandlerCache{System.Data.DataTable}">
<MethodInstantiation Name="SetHandler" Arguments="Dapper.SqlMapper.ITypeHandler" Dynamic="Required" />
</Type>
</Application>
</Directives>
I assume I need to include references to my models here which would be Foo and Bar, but the error getting thrown refers to Dapper specifically.
The rd.xml file is inside of my project directory, and is referenced in the MyProject.csproj like so:
<ItemGroup>
<EmbeddedResource Include="rd.xml" />
</ItemGroup>
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?
Try add this to directives: