【发布时间】: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,任何人都可以帮助告诉我如何正确实现这个构建?
【问题讨论】:
-
此错误意味着您应该在文件 [ProjectName].rd.xml(属性文件夹)中向 .Net Native 添加有关类的附加信息。在此处查看更多信息msdn.microsoft.com/en-us/library/dn600639(v=vs.110).aspx
标签: linq visual-studio-2015 win-universal-app entity-framework-core .net-native