autofac / Autofac

An addictive .NET IoC container
https://autofac.org
MIT License
4.44k stars 836 forks source link

[Xamarin.iOS] Application crashes during apple review process #1398

Closed lanarchyste closed 9 months ago

lanarchyste commented 9 months ago

Hi,

I have a Xamarin project to create an Android and iOS application. In this project I use Autofac 7.1.0.

But Apple refuses to deploy iOS app due to startup crash.

According to the logs, it may be linked to Autofac.

5    Kibati.iOS                              0x10a275c88 mono_handle_exception_internal + 101440648 (mini-exceptions.c:2783)
6    Kibati.iOS                              0x10a27465c mono_handle_exception + 101434972 (mini-exceptions.c:3107)
7    Kibati.iOS                              0x10a26a354 mono_arm_throw_exception + 101393236 (exceptions-arm64.c:403)
8    Kibati.iOS                              0x1044468dc throw_exception + 172
9    Kibati.iOS                              0x105fb7510 Autofac_Builder_StartableManager_StartStartableComponents_System_Collections_Generic_IDictionary_2_string_object_Autofac_IComponentContext + 31454480 (/<unknown>:1)
10   Kibati.iOS                              0x10601d118 Autofac_Autofac_ContainerBuilder_Build_Autofac_Builder_ContainerBuildOptions + 248
11   Kibati.iOS                              0x10a287a4c mono_jit_runtime_invoke + 101513804 (mini-runtime.c:3191)
12   Kibati.iOS                              0x10a341698 mono_runtime_invoke_checked + 102274712 (object.c:3220)
13   Kibati.iOS                              0x10a344ed8 mono_runtime_invoke + 102289112 (object.c:3107)
14   Kibati.iOS                              0x1042a9204 native_to_managed_trampoline_16(objc_object*, objc_selector*, _MonoMethod**, objc_object*, objc_object*, unsigned int) + 987652 (registrar.m:833)
15   Kibati.iOS                              0x1042a9914 -[AppDelegate application:didFinishLaunchingWithOptions:] + 989460 (registrar.m:11524)

I don't encounter any crashes with a iOS simulator or iOS physical hardware. There is only apple when reviewing the application which encounters the crash. I have no problems with the Android application which has the same version of Autofac.

The material used for the iOS review is:

My code to initialize Autofac has the following parts:

var builder = new ContainerBuilder();
...
builder.RegisterType<...>().As<...>();
builder.RegisterType<...>().As<...>().SingleInstance();
builder.RegisterType<...>().As<...>().AsSelft();
builder.RegisterType<...>().As<...>().AutoActivate();
...
var resolver = new AutofacResolver(builder.Build());
Resolver.SetResolver(resolver);

Do you think that Autofac really has a bug with the Apple review process?

Thanks !

Best Regards, Julien

alistairjevans commented 9 months ago

iOS does not permit dynamic code generation at runtime, which Autofac uses in a variety of places, including when activating types defined via RegisterType and in AutoActivate.

If you restrict yourself to delegate registrations, e.g. Register(ctxt => new ...), and don't use AutoActivate, you may have some luck, but in general Autofac is not fully supported in no-emit environments.