Monotouch 中的 Linq(在设备上调试)

标签 linq xamarin.ios jit aot azure-mobile-services

我正在尝试运行 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/

相关文章:

c# - 如何使用 linq-to-xml 更改标签名称和获取属性

.net - Objective-C to Monotouch (.NET) 单行代码转换

visual-studio - 设备的 Ad-Hoc 代码设计在 Studio 中成功,在 Jenkins 中失败

c# - 奇怪的 HttpWebResponse 错误 : ServerProtocolViolation

python - 当类的属性包含 self 的实例时如何指定 numba jitclass

java - JVM 或 JIT 是否能够减少重复的方法调用?

c# - 如何在 LINQ 中对单个连接中的多个字段进行连接

c# - EF Core 选择一个由相关实体过滤的实体

c# - LINQ 左 JOIN 错误

c# - ref 如何/为什么返回实例成员