CommunityToolkit / MVVM-Samples

Sample repo for MVVM package
Other
1.11k stars 222 forks source link

Null exception on Ioc.Default.ConfigureServices on Android after return from OnDestroy #81

Open sergsel opened 2 years ago

sergsel commented 2 years ago

System.InvalidOperationException: The default service provider has already been configured at Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.ThrowInvalidOperationExceptionForRepeatedConfiguration () [0x00000] in //Microsoft.Toolkit.Mvvm/DependencyInjection/Ioc.cs:164 at Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.ConfigureServices (System.IServiceProvider serviceProvider) [0x0000f] in //Microsoft.Toolkit.Mvvm/DependencyInjection/Ioc.cs:139 at CSLightsMVVM.App..ctor () [0x00009] in C:\Users\Tom\source\repos\CSLightsMVVM\CSLightsMVVM\CSLightsMVVM\App.xaml.cs:29

The problem is that Ioc.Default object is instantiated itself and apparently not destroyed after MainActivity.OnDestroy() is called. Then, when user return app from stack, App ctor is run again and there no way to check if Ioc.Default had been already configured or not.