我正在尝试运行 Windows Azure 移动服务查询(使用 SDK 的 xamarins monotouch fork)。
这段代码在模拟器上运行良好,但在设备上却崩溃了:
this.table.Where (a => a.Sequence == sequence).Where (a => a.Week == week).ToListAsync()
.ContinueWith (t =>
{
this.items = t.Result;
this.tableView.ReloadData ();
IsUpdating = false;
}, scheduler);
我得到的错误是:
Exception has been thrown by the target of an invocation. ---> System.Exception: Attempting to JIT compile method 'System.Linq.jvm.Runner:GetDelegate ()' while running with --aot-only.
我唯一能做的就是删除 where 条件。 这工作得很好,除了我(显然)没有根据需要过滤结果。
我应该如何重写我的代码以使其在实际的 iOS 设备上运行?
更新: table 是 *IMobileServiceTable < Activity > *
类型的类变量week和sequence都是int类型。
Activity 是一个 POCO 类。
public class Activity
{
public int ID {
get;
set;
}
public string Name {
get;
set;
}
public int CaloricRequirementMin {
get;
set;
}
public int CaloricRequirementMax {
get;
set;
}
public string Difficulty {
get;
set;
}
public int PlanId {get;set;}
public string Type {
get;
set;
}
public int Sequence {
get;
set;
}
public int Week {
get;
set;
}
public int SubscriptionActivityId {
get;
set;
}
}
我已经仔细检查以确保这些都已填充。
它在模拟器上完美地表达。
最佳答案
MonoTouch Ahead Of Time (AOT) 编译器的全部目的是为了避免 Apple 不允许在 iOS 中编译的问题。它是多种安全策略之一,其他策略还有签名的可执行文件、应用程序审查、沙箱等。不幸的是,某些 LINQ 表达式需要 JIT 编译,因此无法在设备上运行。
所有 LINQ 表达式都可以转换为非 LINQ(通常是迭代)代码。在转换为迭代之前,您可以考虑一些可能有效的 LINQ 替代方案,例如 Any() 表达式。
关于Monotouch 中的 Linq(在设备上调试),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14325048/