MissingMetadataException when building UWP app with .Net native
<p>I have this UWP app that uses a project (UWP class library) which itself uses EF7 and SQLite.</p>

<p>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.</p>

<p>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 <a href="https://stackoverflow.com/questions/34748389/uwp-net-native-tool-chain-compilation-error">UWP - .NET Native tool chain compilation error</a></p>

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

<p>This time I got hit by this famous <code>MissingMetadataException</code> :</p>

<p><a href="https://i.stack.imgur.com/e25hE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e25hE.jpg" alt="enter image description here"></a></p>

<p>The output window shows this :</p>

<blockquote>
<pre><code>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
</code></pre>
  
  <p>metadata. For more information, please visit
  <a href="http://go.microsoft.com/fwlink/?LinkID=392859" rel="nofollow noreferrer">http://go.microsoft.com/fwlink/?LinkID=392859</a></p>
</blockquote>

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

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

      if (sortedArticles != null &amp;&amp; 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;
      }
}
</code></pre>

<p>This method above is called inside an Async method, just to know.</p>

<p>I tried, desperately, to call .ToList() by doing :</p>

<pre><code>var sortedArticles = DbContext.Articles.ToList().OrderByDescending(article =&gt; article.ArticlePubDate).ToList();
</code></pre>

<p>But still get the same error.</p>

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