我目前有一些代码,如下所示,使用Linq来为我组织一些IEnumerables。 当在设备上以发布模式(iOS 5.0.1,MonoTouch 5.0.1,Mono 2.10.6.1)执行此代码时,会出现以下异常
尝试使用--aot-only运行时编译方法“System.Linq.OrderedEnumerable`1:GetEnumerator()”。
导致此错误的代码是:
// List<IncidentDocument> documents is passed in
List<LibraryTableViewItemGroup> groups = new List<LibraryTableViewItemGroup>();
List<DocumentObjectType> categories = documents.Select(d=>d.Type).Distinct().OrderBy(s=>s.ToString()).ToList();
foreach(DocumentObjectType cat in categories)
{
List<IncidentDocument> catDocs = documents.Where(d => d.Type == cat).OrderBy(d => d.Name).ToList();
List<LibraryTableViewItem> catDocsTableItems = catDocs.ConvertAll(d => { return new LibraryTableViewItem{ Image = GetImageForDocument(d.Type), Title = d.Name, SubTitle = d.Description}; });
LibraryTableViewItemGroup catGroup = new LibraryTableViewItemGroup{ Name = GetCatName(cat), Footer = null, Items = catDocsTableItems };
groups.Add (catGroup);
}
这个错误在Release|Debug配置的模拟器中不会发生,也不会在Debug配置的设备上发生。我在Stack Overflow看到了几个类似的帖子这里和这里,但我不确定它们如何适用于我在这个特定问题上。
.ToList<DocumentObjectType>()
而不是.ToList()
,那么这是否足够让编译器正确地AOT这些类型呢? - pseabury