DryIoc icon indicating copy to clipboard operation
DryIoc copied to clipboard

Exception: Window already exists

Open ChristianM66 opened this issue 1 year ago • 5 comments

Hello, I am using DryIoC in conjunction with IServiceColleciotn in net8 and Maui. When merging DryIoC and IServiceCollection using IContainer.Populate the following exception is thrown .

Without DryIoC and the Populate call, the exception does not occur.

Many thanks for your help

StackTrace at Microsoft.Maui.Controls.Window.Microsoft.Maui.IWindow.Created() at Microsoft.Maui.LifecycleEvents.AppHostBuilderExtensions.<>c.<OnConfigureLifeCycle>b__2_0(Window window) at Microsoft.Maui.Platform.ApplicationExtensions.<>c__DisplayClass1_0.<CreatePlatformWindow>b__1(OnWindowCreated del) at Microsoft.Maui.LifecycleEvents.LifecycleEventServiceExtensions.InvokeLifecycleEvents[TDelegate](IServiceProvider services, Action`1 action) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, OpenWindowRequest args) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(Application platformApplication, IApplication application, LaunchActivatedEventArgs args) at Microsoft.Maui.MauiWinUIApplication.OnLaunched(LaunchActivatedEventArgs args) at Microsoft.UI.Xaml.Application.Microsoft.UI.Xaml.IApplicationOverrides.OnLaunched(LaunchActivatedEventArgs args) at ABI.Microsoft.UI.Xaml.IApplicationOverrides.Do_Abi_OnLaunched_0(IntPtr thisPtr, IntPtr args)

ChristianM66 avatar Jun 11 '24 14:06 ChristianM66

What is the exception message?

dadhi avatar Jun 11 '24 14:06 dadhi

What is the exception message? The exception message is: Window already exists.

The error occurs under net8 regardless of which versions of DryIoC and DryIoc.Microsoft.DependencyInjection are used.

ioCManager encapsulates DryIoC.IContainer and is registered in DryIoContainer itself.

DryIoC: 5.4.3 DryIoc.Microsoft.DependencyInjection: 6.2.0

Configuration: private IocManager() { this.Container = new Container(_ => Rules.Default.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient). With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments)). WithFuncAndLazyWithoutRegistration(). WithTrackingDisposableTransients(). WithFactorySelector(Rules.SelectLastRegisteredFactory()). WithMicrosoftDependencyInjectionRules(). WithUseInterpretation()); }

or DryIoC: 6.0.0-preview-07 DryIoc.Microsoft.DependencyInjection: 8.0.0-preview-02

Configuration private IocManager() { Rules rules = DryIocAdapter.MicrosoftDependencyInjectionRules.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient). With(Made.Of(FactoryMethod.ConstructorWithResolvableArguments)). WithFuncAndLazyWithoutRegistration(). WithTrackingDisposableTransients(). WithFactorySelector(Rules.SelectLastRegisteredFactory()). WithUseInterpretation();

this.Container = new Container(rules) }

When I call Populate (iocManager.Container.Populate(mauiAppBuilder.Services);) the exception is thrown.

I have been working successfully with DryIoc, Xamarin, netStandard, AspNet.Core since 2019. The error occurs with net8 and Maui.

No matter which platform (Windows Machine, Android, iOS) is used

ChristianM66 avatar Jun 12 '24 05:06 ChristianM66

@ChristianM66

Thanks for the clarifying. Sadly, nor exception message, nor the stack trace contains any DryIoc related information. I would suggest to search MAUI code for specifics of the "Window already exists" condition.

Also in regard to the Rules.Default.WithConcreteTypeDynamicRegistrations(reuse: Reuse.Transient). Could you remove it and check again?

dadhi avatar Jun 12 '24 11:06 dadhi

@ChristianM66 Hi, I want to suggest trying DryIoc v6.0.0-preview-07 and check if the issue is reproducible.

dadhi avatar Jun 27 '24 10:06 dadhi

@ChristianM66 any updates on the issue?

dadhi avatar Aug 29 '24 19:08 dadhi

Closing as there is no updates from the issue author.

dadhi avatar Mar 03 '25 16:03 dadhi