Search code examples
c#.netxamarininversion-of-controldryioc

Operation is not supported on this platform exception on Xamarin iOS


I am using DryIoC container, and while trying to resolve one of the implementations am getting below error:

Operation is not supported on this platform exception on Xamarin iOS

The resolve work's fine for the first time, but when I try to call resolve the second time it is giving this exception.

Below is how I am registering:

container.Register<IFoo, Foo>(Reuse.ScopedOrSingleton);

Resolve Call:

container.Resolve<IFoo>()

I checked that there's already a bug reported in for this in the Github.

As per one of the comments on that discussion I implemented below code and after that, it seems to be working fine, but I am not sure what is the purpose of setting this rule and is there any drawback for setting this rule.

var container = new Container(rules => rules.WithoutFastExpressionCompiler());

Solution

  • Xamarin iOS does not support IL Emit and DynamicMethod compilation, which is the default DryIoc mechanism for object graph creation (via invoking the compiled delegate). But the compilation may be replaced by interpretation "sacrificing" some of the compiled delegated performance. The sacrifice is not so straightforward and depends on your case, moreover interpretarion is used for the first-time resolution anyway because compilation itself is costly. For more details and performance numbers you may look here: https://github.com/dadhi/DryIoc/issues/199#issuecomment-573291497

    Side note: DryIoc uses its own specialized interpretation model and does not rely on System.Linq.Exptessions.Expression.Compile(preferInterpretation: true) which makes it much faster.