I'm receiving the following error on my iOS device:
ExecutionEngineException: Attempting to JIT compile method 'System.Linq.OrderedEnumerable
1<System.Collections.Generic.KeyValuePair
2>:GetEnumerator ()' while running with --aot-only.
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.
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;
}
}
However, using OrderBy still gives me the error. Is there something I'm not understanding on why my method doesn't work?
My expression:
OptimizeMaxCommitList(members
.OrderBy((memberid) => memberid.Value, new IntCompare())
.Skip(1)
.ToDictionary(pair => pair.Key, pair => pair.Value)
,maxCommit);
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With