LINQ Order的JIT错误通过在iOS上使用C# [英] JIT error with LINQ OrderBy using C# on iOS

查看:105
本文介绍了LINQ Order的JIT错误通过在iOS上使用C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS设备上收到以下错误:

I'm receiving the following error on my iOS device:

ExecutionEngineException:仅与--aot一起运行时,尝试JIT编译方法'System.Linq.OrderedEnumerable 1<System.Collections.Generic.KeyValuePair 2>:GetEnumerator()'.

ExecutionEngineException: Attempting to JIT compile method 'System.Linq.OrderedEnumerable1<System.Collections.Generic.KeyValuePair2>:GetEnumerator ()' while running with --aot-only.

我正在使用Unity3D,并且我知道是由于LINQ表达式在将Unity编译为iOS时排序值类型方面的问题而引起的.因为(我认为)该表达式尝试使用反射来实例化实现IComparer< TKey>接口的新类型.这将适用于引用类型,但不适用于Unity iOS构建中的值类型.

I'm using Unity3D, and I know the error is caused because LINQ expressions have issues with ordering value types when compiling Unity to iOS. Because (I think) that the expression attempts to use reflection to instantiate a new type which implements the IComparer<TKey> interface. This will work for reference types, but not value types on a Unity iOS build.

所以我的想法是,由于我知道在这种情况下,我一直在尝试订购一个整数集合.我可以绕过通用的ICompare< TKey>并只创建自己的自定义比较器.

So my thought was that since I know in this situation I'm always trying to order a collection of ints. That I could bypass the generic ICompare<TKey> and just create my own custom comparer.

public class IntCompare : Comparer<int> {

    public override int Compare (int x, int y)
    {
       return x - y;
    }
}

但是,使用OrderBy仍然会给我错误.关于我的方法为什么行不通,我是否不了解?

However, using OrderBy still gives me the error. Is there something I'm not understanding on why my method doesn't work?

我的表情:

OptimizeMaxCommitList(members
                            .OrderBy((memberid) => memberid.Value, new IntCompare())
                            .Skip(1)
                            .ToDictionary(pair => pair.Key, pair => pair.Value)
                    ,maxCommit);

推荐答案

LINQ for Collections的大多数LINQ扩展方法不适用于iOS上的IEnumerables,因为它们需要不支持的AOT运行时编译器.

Most of LINQ extension methods from LINQ for Collections are not working with IEnumerables on iOS since they require the AOT runtime compiler which is not supported.

但是,Asset Store上有一个 LINQ for iOS 库与LINQ相似,但不需要运行时编译器.因此,您可以在iOS上使用它.

However there is a LINQ for iOS library on Asset Store that is similar to LINQ, but doesn't require a runtime compiler. So you can use it on iOS.

这篇关于LINQ Order的JIT错误通过在iOS上使用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆