MissingMetadataException when building UWP app with .Net native

.net-native entity-framework-core linq visual-studio-2015 win-universal-app

Question

I have this UWP app that uses a project (UWP class library) which itself uses EF7 and SQLite.

I tried to build the app in the Release mode using .Net native tool chain, the build completes successfully (after a good long time, and after eating as much memory as it can), but the application crashes just after leaving the splash screen.

After following some advice on SO I tried the .Net native with Debug mode, the build finishes just like in the Release mode, but I get many errors on the output window and it is the same scenario as this one UWP - .NET Native tool chain compilation error

I followed @Matt Whilden advice, and I got rid of those errors, then tried again.

This time I got hit by this famous MissingMetadataException :

enter image description here

The output window shows this :

Exception thrown: 'System.AggregateException' in System.Private.Threading.dll
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll
Exception thrown: 'System.ArgumentException' in System.Linq.Expressions.dll
The thread 0x2a30 has exited with code 0 (0x0).
Exception thrown: 'System.Reflection.MissingMetadataException' in System.Private.Reflection.Core.dll
Additional information: 'Microsoft.Extensions.Caching.Memory.MemoryCacheOptions' is missing

metadata. For more information, please visit http://go.microsoft.com/fwlink/?LinkID=392859

I tried to follow my code, during execution and I found out that it is caused by the first ever call to a DbSet table from my DbContext

public long GetLastTimeStamp()
{
      //-----> Here is the line causing the error
      var sortedArticles = DbContext.Articles.OrderByDescending(article => article.ArticlePubDate).ToList();

      if (sortedArticles != null && sortedArticles.Count != 0)
      {
           DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local);

           TimeSpan elapsedTime = sortedArticles.First().ArticlePubDate - epoch;
           return (long)elapsedTime.TotalSeconds;
      }
      else
      {
          return 0;
      }
}

This method above is called inside an Async method, just to know.

I tried, desperately, to call .ToList() by doing :

var sortedArticles = DbContext.Articles.ToList().OrderByDescending(article => article.ArticlePubDate).ToList();

But still get the same error.

This is really frustrating, I don't know how to solve this problem, not sure what and how I should change the Default.rd.xml, any one can help telling me how to achieve this build correctly ?

1
0
5/23/2017 10:33:58 AM

Accepted Answer

Please try to add type 'Microsoft.Extensions.Caching.Memory.MemoryCacheOptions' in Default.rd.xml (already present in your project).

cf. https://blogs.msdn.microsoft.com/dotnet/2014/05/21/net-native-deep-dive-help-i-hit-a-missingmetadataexception/

For example:

<?xml version="1.0" encoding="utf-8"?>
<Directives xmlns="http://schemas.microsoft.com/netfx/2013/01/metadata">
   <Application>
      <Type Name="Microsoft.Extensions.Caching.Memory.MemoryCacheOptions" Dynamic="Required All" />
   </Application>
</Directives> 
3
3/23/2016 11:54:39 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow