- Home /
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 :
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.I tried to call the first visible method explicitly, but It provokes the same issue.
I tried to use a custom
IScheduler
(which use the Unity's coroutine system to schedule items) that will not call theSystem.Reactive.Concurrency.CurrentThreadScheduler
(the default scheduler that create the issue). In order to force the use of this scheduler, I calledSubscribeOn
andObserveOn
on allSubject
I use asIObservable
. But, the issue still happens onSubscribe
call.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.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 !
Answer by JaredThirsk · Oct 22, 2013 at 05:49 AM
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.
Your answer
Follow this Question
Related Questions
Saving Data on IOS produces JIT Error in Xcode 2 Answers
Failed to load AOT module 'mscorlib' while running in aot-only mode 0 Answers
Loading scripts dynamically in AoT compilers 1 Answer
Is it possible to use LUA or JS to bypass AOT limitations on iOS? 1 Answer
iOS JIT compile error on Generic method called with basic types (int, bool, float) 1 Answer