System.ExecutionEngineException: Attempting to JIT compile method System.Linq.Enumerable

关于JIT编译和AOT编译的问题。IOS下是不支持JIT动态编译的,所以如果程序有涉及JIT编译的都会无法执行。

在google查过说unity是不支持部分的Linq功能,如Sort方法。

但我在unity里面没有用到Linq的Sort方法,不过有用到OrderBy, FirstOrDefault, Where等。结果还是出现这个错误,

以防万一只能将所有用到的Linq方法重写。

如:类似System.Linq.Enumerable.Where的方法

public static IEnumerable<T> Filter<T>(this IEnumerable<T> source, Func<T, bool> predicate)    
        {
            if (source == null || predicate == null)
            {
                throw new ArgumentNullException();
            }
            return impl(source, predicate);
        }

        private static IEnumerable<T> impl<T>(IEnumerable<T> source, Func<T, bool> predicate)
        {
            foreach (T item in source)
            {
                if (predicate(item))
                {
                    yield return item;
                }
            }
        }

Since applications on the iPhone using Xamarin.iOS are compiled to static code, it is not possible to use any facilities that require code generation at runtime. 

From: http://developer.xamarin.com/guides/ios/advanced_topics/limitations/

原文地址:https://www.cnblogs.com/vincentDr/p/4096767.html