【问题标题】:MissingMetadataException when building UWP app with .Net native使用 .Net native 构建 UWP 应用程序时出现 MissingMetadataException
【发布时间】:2016-07-10 15:45:57
【问题描述】:

我有这个 UWP 应用程序,它使用一个项目(UWP 类库),该项目本身使用 EF7 和 SQLite。

我尝试使用 .Net 原生工具链在 Release 模式下构建应用程序,构建成功完成(经过很长时间,并且在消耗了尽可能多的内存之后),但应用程序在离开后立即崩溃启动画面。

在遵循一些关于 SO 的建议后,我尝试了带有调试模式的 .Net 本机,构建完成就像在发布模式下一样,但是我在输出窗口上遇到了很多错误,这与UWP - .NET Native tool chain compilation error 的情况相同

我听从了@Matt Whilden 的建议,并摆脱了这些错误,然后再次尝试。

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

输出窗口显示:

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

我在执行期间尝试跟踪我的代码,我发现这是由我的 DbContext 中第一次调用 DbSet 表引起的

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方法内部调用的,只是为了知道。

我拼命地尝试通过这样做来调用 .ToList():

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

但仍然得到同样的错误。

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

【问题讨论】:

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


【解决方案1】:

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

参见。 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> 

【讨论】:

    猜你喜欢
    • 2016-05-28
    • 2019-01-30
    • 2018-06-11
    • 2020-06-10
    • 1970-01-01
    • 1970-01-01
    • 2020-02-09
    • 2022-07-07
    • 2020-04-07
    相关资源
    最近更新 更多