2

我正在尝试运行 Windows Azure 移动服务查询(使用 SDK 的 xamarins monotouch 分支)。

此代码在模拟器上运行良好,但在设备上崩溃了:

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);

我得到的错误是:

调用的目标已引发异常。---> System.Exception:在使用 --aot-only 运行时尝试 JIT 编译方法“System.Linq.jvm.Runner:GetDelegate ()”。

我设法使它工作的唯一一件事就是删除 where 条件。这工作得很好,除了我(显然)没有根据需要过滤结果。

我应该如何重写我的代码以使其在实际的 iOS 设备上运行?

更新:表是类型的类变量 * 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;
        }
}

我已经仔细检查以确保这些都已填充。

它在模拟器上完美无瑕。

4

2 回答 2

1

MonoTouch Ahead Of Time (AOT) 编译器的全部意义在于避免 Apple 不允许在 iOS 中编译的问题。它是多个安全策略之一,还有签名的可执行文件、应用程序审查、沙盒等。不幸的是,某些 LINQ 表达式需要 JIT 编译,因此无法在设备上运行。

所有 LINQ 表达式都可以转换为非 LINQ(通常是迭代的)代码。在转换为迭代之前,您可以考虑一些可能有效的 LINQ 替代方法,例如 Any() 表达式。

于 2013-01-15T00:47:24.583 回答
1

最后,我不得不修改我的代码以使用带有字符串查询的 ReadAsync 而不是 linq 表达式。

this.table.ReadAsync(query)
                .ContinueWith (t =>
            {
                    items = (from item in t.Result.GetArray()
                             let act = item.GetObject()
                    select new Activity{
                        ID= Convert.ToInt32(act.GetNamedNumber("id")),
                        Name= act.GetNamedString("Name"),
                        SubscriptionActivityId = act.ContainsKey("SubscriptionActivityId") ? Convert.ToInt32(act.GetNamedNumber("SubscriptionActivityId")) : 0
                    }).ToList();


                    this.tableView.ReloadData ();
                IsUpdating = false;
            }, scheduler);
于 2013-01-15T21:40:49.990 回答