How to use Reactive Extensions on iOS ?

Hi everyone,

I want to use the Reactive Extensions of Microsoft to use the Reactive Programming pattern.
I imported the dll (at version 1.0, which is compatible with dotnet Framework 3.5) and it work perfectly on platform where JIT is available.

But, for iOS, the JIT compiler is not available and I ran into the error :

Attempting to JIT compile method
'System.Reactive.Concurrency.ScheduledItem`2<System.DateTimeOffset, System.Action>:.ctor(System.Reactive.Concurrency.IScheduler, System.Action, System.Func`3<System.Reactive.Concurrency.IScheduler, System.Action, System.IDisposable>, System.DateTimeOffset)' while running with --aot-only

The actual issue is that a generic method is called (System.Reactive.Concurrency.ScheduledItem:.ctor) with a value type as parameter (System.DateTimeOffset which is a struct) and such calls need to be generated by the JIT compiler

I tried several solutions, but they did not succeeded :

  1. I first wanted to for the aot compiler to include the required method. But, System.Reactive.Concurrency.ScheduledItem is not visible, so I can not reference the class.
  2. I tried to call the first visible method explicitly, but It provokes the same issue.
  3. I tried to use a custom IScheduler (which use the Unity’s coroutine system to schedule items) that will not call the System.Reactive.Concurrency.CurrentThreadScheduler (the default scheduler that create the issue). In order to force the use of this scheduler, I called SubscribeOn and ObserveOn on all Subject I use as IObservable. But, the issue still happens on Subscribe call.
  4. I wanted to replace somehow the default IScheduler, but It seems not possible to replace it. Anyway, I did not find a way to do it.
  5. I planned to implement myself a subset of Rx features which would be simple and synchronous. But, it is a loss of time to reproduce a framework that already exists and was done by an entire team of Microsoft.

Currently, my plan is to create my own implementation. Well, this is not a good solution, but I did not find another way. Moreover, it raise another issue : How to choose a dll in the Assets folder depending on the platform selected ? (ie : I want to use Microsoft’s dll for jit platform and my implementation for aot platforms)

Well, I am a kind of stuck here, any idea will be greatly appreciated !

This discussion suggests that the outdated version of Mono that Unity3D uses (2.6) has problems with Rx:
https://rx.codeplex.com/discussions/406013

Also, there are known issues with older (and newer?) versions of mono and generic interfaces on AOT (for iOS.)

Also, there are issues with older versions of mono and structs in generic interfaces. I would try wrapping DateTimeOffset in a class (reference type.) I believe this has been addressed in the latest versions of mono.