MissingMetadataException when using EntityFrameworkCore with SQLite #6477
Comments
There is a piece of RD.XML that will likely fix the issue you're seeing over in issue #6459 (the line with See the WebApi sample CSPROJ file for how to reference the RD.XML from your project: https://github.com/dotnet/corert/tree/master/samples/WebApi |
Alright, I've managed to iteratively add various missing metadata things. My rd.xml now looks like:
However, I'm now getting a TypeInitializationException from Linq:
How would one normally proceed from the backtrace above? I also note that creating the rd.xml was rather a painful process; will this always be required for native compilations? |
Add this to your project file: <ItemGroup>
<!-- Do not generate partial metadata for types - always include all members even if they're unused -->
<IlcArg Include="--completetypemetadata" />
<!-- Generate extra data to make stack traces nicer -->
<IlcArg Include="--stacktracedata" />
</ItemGroup> (The
You can always do Entity framework is pretty much the reason why we added the universal shared code feature to the ".NET Native for UWP apps" compiler. EF does a lot of generic reflection. |
Alright, thanks for the pointers + options for completetypemetadata and stacktracedata. I've added them to my project and get a more informational backtrace:
Thanks for the help + pointers btw, super insightful stuff too! |
So now it's a generic method - the RD.XML syntax for that is here: #4775. |
Alright, I've added a generic method element to my rd.xml which looks like the following:
After compilation, I now get:
|
Can you try setting the version of the ILCompiler package you reference to 1.0.0-alpha-27012-01 (you probably have |
git diff hello.csproj:
rm -rf obj/ bin/ && dotnet publish -r osx-x64 -c debug && bin/debug/netcoreapp2.1/osx-x64/publish/hello:
|
Oh, okay. Kind of glad it's not a regression. In any case, that's a CoreRT bug. I've opened #6478 to track. |
I retried a build and I can pass the GVM lookup failure now. After another few missed types and generic methods, I end up with something new (for me, at least):
What does the runtime mean by "This object cannot be invoked because it was metadata-enabled for browsing only"? |
This means that we didn't compile the code for the non-generic method on the generic type. Adding a Line 72 in adefdef
|
I've stubbornly soldiered on to add whichever type the runtime comes up with (see latest commit here: https://github.com/rubin55/dot-hello)`. I get a by-now-familiar backtrace:
However, when I try to add
Sorry for taking up so much of your time man, I'm a bit stubborn when trying to get something to work :-) Thanks a lot anyways. |
Your patience is admirable :). Seems like that type lives in the |
Hi Michal, So I marched on and am now stumped by the following Generic Method related exception:
I've commited the latest rd.xml to my dot-hello repository. If I extrapolate the above and add the following:
For the Getter, which is incidentally almost identical to the Setter variant I've added previously, I get this:
It seems to tell me it cannot find System.Int32; Am I specifying it wrongly? As always much appreciated! |
Thanks for keeping at it! I'm wondering how much RD.XML will be needed in the end myself :). Int32 should be referenced as |
Hey Michal, I reached the end! :-). I ran into a total of 99 MissingMetadataExceptions and added 103 Type entries to rd.xml. To run, git clone my dot-hello repository, and:
and then:
It seems to work, but once (could not reproduce) I ran into the following:
When it works, it outputs (multiple runs done before this):
Cool that I got it working but two questions:
|
This is awesome! Good job and thank you! If you would like to contribute your work, we would be happy to accept a pull request adding this to the
That's unfortunate. If you still had the EXE/PDB, we could use the
The RD.XML you came up with is a "minimal RD.XML" - it results in the best executable size and fastest compilation speed, because we only compile what's really needed. You could e.g. replace the 38 If you do this for all the assemblies in your project, the only way you could hit a reflection related issue is in
I assume there's a P/invoke to the SQLite library somewhere - what the compiler/runtime does is that it uses |
Wow - thanks @rubin55, for all your hard work tracking this down and sharing your solution! I was able to resolve my own issues with MissingMetadataException using your rd.xml as a starting point ( linked here as a convenience for future devs: https://raw.githubusercontent.com/rubin55/dot-hello/master/rd.xml ) @MichalStrehovsky - is this the recommended/correct way of resolving this issue? Is there continuing work on this front? |
There's no happy place for Entity Framework right now. It requires writing RD.XML that is specific to each app because the reflection patterns end up being different. Hopefully when Source generators become available, EF will switch to using those instead of reflection. Things will become faster in general and will work better with AOT. (The reflection would be replaced by code generated as part of the build - so instead of reflection-setting each property of the object in the object model, it would be a simple property assignment.) |
I've got a dotnet core 2.1 project where I'm experimenting with creating native static binaries. I'm getting a MissingMetadataException after compilation (using
dotnet publish -r osx-x64 -c debug
):I've read the information on the page referenced in the backtrace, but I can't figure out what to add to my rd.xml. My project is here: https://github.com/rubin55/dot-hello . To reproduce (on macos, I suspect it is the same on other platforms):
I'm wondering if the fact that EntityFramework in this case, having an external dependency on the SQLite .so/.dll/.dylib is the root cause of this, which raises the question: how does one deal with external dependencies like that when using CoreRT?
The text was updated successfully, but these errors were encountered: