使用.Net本机构建UWP应用时缺少MissingMetadataException [英] MissingMetadataException when building UWP app with .Net native

查看:88
本文介绍了使用.Net本机构建UWP应用时缺少MissingMetadataException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用项目(UWP类库)的UWP应用,该项目本身使用EF7和SQLite.

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

我尝试使用.Net本机工具链在发布模式下构建应用程序,构建成功完成(经过很长一段时间,并且在消耗了尽可能多的内存之后),但是在退出应用程序后,应用程序崩溃了启动画面.

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.

在遵循一些建议之后,我尝试使用调试模式运行.Net本机,就像在发布模式下一样完成构建,但是在输出窗口上出现很多错误,并且与该场景相同 UWP-.NET本机工具链编译错误

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

我遵循@Matt Whilden的建议,摆脱了这些错误,然后再次尝试.

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

这次我被这个著名的MissingMetadataException击中了:

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

元数据.欲了解更多信息,请访问 http://go.microsoft.com/fwlink/?LinkID=392859

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

我试图在执行过程中遵循我的代码,但发现这是由我的DbContext第一次调用DbSet表引起的

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;
      }
}

上面的这个方法在Async方法中被称为,

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

我拼命尝试通过执行以下操作来调用.ToList():

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

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

但仍然会出现相同的错误.

But still get the same error.

这真令人沮丧,我不知道如何解决这个问题,不确定我应该怎样更改Default.rd.xml,任何人都可以帮助我告诉我如何正确实现此构建?

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 ?

推荐答案

请尝试在Default.rd.xml中添加类型"Microsoft.Extensions.Caching.Memory.MemoryCacheOptions"(已存在于您的项目中).

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/

例如:

<?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> 

这篇关于使用.Net本机构建UWP应用时缺少MissingMetadataException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆