dadhi / DryIoc

DryIoc is fast, small, full-featured IoC Container for .NET
MIT License
982 stars 122 forks source link

FastExpressionCompiler fails on iOS #604

Closed dansiegel closed 8 months ago

dansiegel commented 8 months ago

Description

When compiling in release mode for net8.0-ios the container is failing with the following error:

PlatformNotSupported_ReflectionEmit
Stacktrace:
at System.Reflection.Emit.AssemblyBuilder.ThrowDynamicCodeNotSupported()
at System.Reflection.Emit.AssemblyBuilder.EnsureDynamicCodeSupported()
at System.Reflection.Emit.DynamicMethod.Init(String name, MethodAttributes attributes, CallingConventions callingConvention, Type returnType, Type[] signature, Type owner, Module m, Boolean skipVisibility, Boolean transparentMethod)
at System.Reflection.Emit.DynamicMethod..ctor(String name, Type returnType, Type[] parameterTypes, Type owner, Boolean skipVisibility)
at DryIoc.FastExpressionCompiler.LightExpression.ExpressionCompiler.CompileNoArgsNew(ConstructorInfo ctor, Type delegateType, Type[] closurePlusParamTypes, Type returnType)
at DryIoc.FastExpressionCompiler.LightExpression.ExpressionCompiler.TryCompileNestedLambda(NestedLambdaInfo nestedLambdaInfo, CompilerFlags setup)

see PrismLibrary/Prism#2987 for a full repro

Note Prism's implementation for the DryIoc container currently uses the following default rules:


public static Rules DefaultRules => Rules.Default.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient)
                                 .With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments))
                                 .WithFuncAndLazyWithoutRegistration()
                                 .WithTrackingDisposableTransients()
                                 .WithFactorySelector(Rules.SelectLastRegisteredFactory());
dadhi commented 8 months ago

Hi, you need to add WithUseInterpretation() for the targets that do not support Emit.

tbaggett commented 8 months ago

@dadhi adding that to the default rules fixed the issue. We had tried adding WithoutUseInterpretation() with no change in the results. We were close! :-) cc @dansiegel

dansiegel commented 8 months ago

Thanks @dadhi