- Home /
JIT exception with ToArray() Linq
Trying to compile to iOS and I'm getting the following exception:
ExecutionEngineException: Attempting to JIT compile method '(wrapper managed-to-managed) UnityEngine.RaycastHit[]:System.Collections.Generic.ICollection`1.CopyTo (UnityEngine.RaycastHit[],int)' while running with --aot-only.
I've done my research and I understand that JIT is "Just In Time", and I need "Ahead Of Time". I know that it's to do with the declaration within my line of code. What I want to know is how I can stop the ToArray() throwing an exception and declare the type?
var hitPoints : RaycastHit[] = Physics.RaycastAll(ray, rayLength, layerMask2).OrderBy(function(h){ return h.distance; }).ToArray();
Answer by Paulius-Liekis · Jul 10, 2012 at 03:40 PM
ToArray(RaycastHit) as RaycastHit[];
Answer by Visartech · Jul 13, 2014 at 12:26 PM
ToArray() is a Linq method.
Most of Linq extension methods from Linq for Collections are not working with IEnumerables on iOS since they require AOT runtime compiler which is not supported.
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 and ToArray() method will work with this library.
Your answer
![](https://koobas.hobune.stream/wayback/20220613074001im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
My Generic function using LINQ(orderBy thenBy)Not working on IOS 1 Answer
Sorting an array using Linq and OrderBy 2 Answers
Saving Data on IOS produces JIT Error in Xcode 2 Answers
Custom functions in SQLite and Unity 1 Answer
ExecutionEngineException : JIT/AOT error when adding to delegate 1 Answer