Search code examples
iphonelinqxamarin.iosjitaot

Monotouch JIT error on device with LINQ


I am trying to run our application on an iOS device through the Debug|iPhone option in MonoTouch. We run into a problem quite fast however. The application crashes with the following exception

Attempting to JIT compile method "System.Linq.Enumerable:<FirstOfDefault`1>m_13<int> (int)" while running with aot-only.

Now I understand this problem comes from the generic part being JIT, which is not allowed on the actual iOS device. What I can't find out though is how to fix it.

Below is the code where it crashes:

int nextTag = (from tag in _cellControllers.Keys
    where tag > currentTag
    select tag).FirstOrDefault();

_cellControllers is a

Dictionary <int, UITableViewSource>

How can I prevent this error from happening?


Solution

  • The problem is having value types as keys in the dictionary, as documented here. Changing the dictionary to not have a value type as key will possibly make this case work (unfortunately in some cases LINQ will use dictionaries by itself, in which case it would be required to rewrite the query).

    We're working on fixing these issues while using LINQ, so I'd also suggest filing a bug with a compilable test case so we can ensure your case works in the future.