Search code examples
c#iphonelinqxamarin.iosaot

Monotouch blows up on LINQ query when using device builds


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.


Solution

  • 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.