AsParallel crashing a MonoTouch app

c#, plinq, task-parallel-library, xamarin.ios

Solution

This is a known limitation with MonoTouch and generics - in this case it's because you're working with structures.

It should work if you use objects instead:

var items = new object [] { 1, 2, 3 };
var twice = (
    from x in items.AsParallel()
    select 2 * x
).ToArray();

We're working on fixing some of these limitations, so it would be nice if you could file a bug report with a sample project for us to have a look to see if it is possible to actually fix this case on day.

Problem

MonoTouch advertises support for `AsParallel` on its website with this code snippet: ``` from item in items.AsParallel () let result = DoExpensiveWork (item) select result; ``` However, even a trivial sample crashes my app: ``` var items = new [] { 1, 2, 3 }; var twice = ( from x in items.AsParallel() select 2 * x ).ToArray(); ``` I know MonoTouch can't handle virtual generic methods but isn't PLINQ supposed to work? What is it wrong that I am doing? MonoTouch version is 5.3.5. Same goes for `Parallel.ForEach`: ``` System.AggregateException: One or more errors occured ---> System.Exception: Attempting to JIT compile method 'System.Threading.Tasks.Parallel:<ForEach`1>m__36<int> ()' while running with --aot-only. See http://docs.xamarin.com/ios/about/limitations for more information. ```

Original source