使用设备构建时,Monotouch 在 LINQ 查询上崩溃

发布于 2024-11-27 23:13:01 字数 330 浏览 1 评论 0原文

这是我收到的错误:

| mscorlib | |在使用 --aot-only 运行时尝试 JIT 编译方法 'System.Linq.OrderedEnumerable`1:GetEnumerator ()'。

从我读到的内容看来,编译器在本例中不包含“GetEnumerator”方法,而代码由于 LINQ 的原因需要该方法。确保编译器包含它的正确做法是什么?

我在网上找到的几乎所有遇到此问题的人都摆脱了 linq 查询并继续生活,但当出现类似的情况时,我厌倦了重写我的代码。另外,我不确定到底是哪个 linq 查询导致了问题,我正在慢慢地检查我的代码并重写所有 linq 查询,直到找到它。

Here's the error I get:

| mscorlib | | Attempting to JIT compile method 'System.Linq.OrderedEnumerable`1:GetEnumerator ()' while running with --aot-only.

From what I've read it looks like the compiler doesn't include a method in this case "GetEnumerator", that the code needs because of LINQ. What is the correct course of action for making sure the compiler includes it?

Pretty much everyone that runs into this that I've found online just gets rid of the linq query and moves on with life but I am tired of re-writing my code when something like this pops up. Also I'm not sure exactly which linq query is causing the issue and I'm slowly going through my code and re-writing all the linq queries until I find it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

未蓝澄海的烟 2024-12-04 23:13:01

GetEnumerator 方法并没有真正丢失 - 但它在进入设备之前没有经过 AOT 处理。所以 JIT 正在尝试在设备上编译它。现在,由于 Apple 的限制,MonoTouch(或其他任何东西)无法在设备上进行 JIT 代码(但这将在不存在此类限制的模拟器上运行)。

那么真正的错误是什么:AOT 编译器无法预测(并为其编译代码)的(通用)类型。

找到问题的一个技巧(比重写每个 LINQ 代码更容易)是编译 C# 代码,然后对程序集进行 ildasm。接下来查找正在使用哪些方法 OrderedEnumerable`1(LINQ 可以非常轻松地隐藏内容)。

一旦发现,您可能需要重写该部分,但在某些情况下,您可以通过使需要的类型(由“1”表示)更加明显来“帮助”AOT 编译器。

The GetEnumerator method is not really missing - but it was not AOT-ed before getting into the device. So the JIT is trying to compile it on the device. Now due to Apple restriction MonoTouch (or anything else) cannot JIT code on devices (but that will work on the simulator where no such restriction exists).

So what's the real error: it's that (generic) type hat the AOT compiler could not predict (and compile code for it).

A trick to find your issue (easier than re-writing every LINQ code you have) is to compile your C# code and then ildasm the assembly. Next find in which method(s) OrderedEnumerable`1 is being used (LINQ can hide things very easily).

Once found you might need to rewrite that part but, in some cases, you can "help" the AOT compiler by making it more obvious that the type (represented by `1) will be needed.

一抹苦笑 2024-12-04 23:13:01

#17 在这个链接中对您有帮助吗?

http://ios.xamarin.com/Documentation/Troubleshoot

“System.ExecutionEngineException:尝试 JIT编译方法(包装器托管到托管)Foo[]:System.Collections.Generic.ICollection`1.get_Count()"

您可能很需要“破解”遗憾的是,解决此问题的解决方法 - 但它是可以修复的。您能用实际的 LINQ 查询更新您的问题吗?

Does number #17 help you in this link?

http://ios.xamarin.com/Documentation/Troubleshoot

"System.ExecutionEngineException: Attempting to JIT compile method (wrapper managed-to-managed) Foo[]:System.Collections.Generic.ICollection`1.get_Count()"

You may well need to "hack" a workaround to fix this, sadly - but it is fixable. Can you please update your question with the actual LINQ query?

吾性傲以野 2024-12-04 23:13:01

发现有问题的代码行:

// currentDates is a List
return (from dt in currentDates orderby dt.Date ascending select dt).ToList();

我将其更改为使用

CurrentDates.Sort()

,避免调用未获得 AOT 的 GetEnumerator。不再炸了。

Found the offending line of code:

// currentDates is a List<DateTime>
return (from dt in currentDates orderby dt.Date ascending select dt).ToList();

I changed it to use

CurrentDates.Sort()

and that avoided calling the GetEnumerator that wasn't getting AOT-ed. No longer blows up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文