MissingMetadataException when building UWP app with .Net native

你说的曾经没有我的故事 提交于 2019-12-11 23:27:50

问题


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 :

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:


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> 


来源:https://stackoverflow.com/questions/36176696/missingmetadataexception-when-building-uwp-app-with-net-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!