PrismLibrary / Prism

Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in WPF, Xamarin Forms, and Uno / Win UI Applications..
Other
6.32k stars 1.64k forks source link

DryIoc.ContainerException on startup when injecting IEventAggregator #3257

Closed munkii closed 1 month ago

munkii commented 1 month ago

Description

I get multiple DryIoc.ContainerException when my MAUI app is starting up. They all say the same thing.

DryIoc.ContainerException: 'code: Error.UnableToResolveUnknownService; message: Unable to resolve Prism.Events.IEventAggregator as parameter "eventAggregator" (IsSingletonOrDependencyOfSingleton)

If I do not have "Break On All Errors" switched On this exception does not break obviously but nor does it even appear in the Debug output.

I have always ran with "Break When Thrown" swicth edon for all CLR exceptions so that I can catch stuff that is getting "swept under the carpet". Is it time to drop that habit?

Steps to Reproduce

Simply run the app and have Break When Thrown switched on for All Exceptions

Platform with bug

.NET MAUI

Affected platforms

Android

Did you find any workaround?

Yes, stop looking for uncaught errors!

Relevant log output

0x12 in DryIoc.Throw.It at /_/src/DryIoc/Container.cs:14774,13  C#
    0xB1 in DryIoc.Container.TryThrowUnableToResolve at /_/src/DryIoc/Container.cs:935,17   C#
    0x6E in DryIoc.Container.DryIoc.IContainer.ResolveFactory at /_/src/DryIoc/Container.cs:915,17  C#
    0x483 in DryIoc.ReflectionFactory.CreateExpressionOrDefault at /_/src/DryIoc/Container.cs:12082,17  C#
    0x2B3 in DryIoc.Factory.GetExpressionOrDefault at /_/src/DryIoc/Container.cs:11038,13   C#
    0x491 in DryIoc.ReflectionFactory.CreateExpressionOrDefault at /_/src/DryIoc/Container.cs:12082,17  C#
    0x2B3 in DryIoc.Factory.GetExpressionOrDefault at /_/src/DryIoc/Container.cs:11038,13   C#
    0x491 in DryIoc.ReflectionFactory.CreateExpressionOrDefault at /_/src/DryIoc/Container.cs:12082,17  C#
    0x2B3 in DryIoc.Factory.GetExpressionOrDefault at /_/src/DryIoc/Container.cs:11038,13   C#
    0x55 in DryIoc.ContainerTools.Validate at /_/src/DryIoc/Container.cs:4521,21    C#
    0xDE in DryIoc.ContainerTools.Validate at /_/src/DryIoc/Container.cs:4493,13    C#
    0x37 in Prism.Container.DryIoc.DryIocContainerExtension.Populate at /_/src/Prism.Container.DryIoc/DryIocContainerExtension.microsoft.cs:27,9    C#
    0x15 in Prism.Ioc.MicrosoftDependencyInjectionExtensions.Populate at /_/src/Prism.Container.Abstractions/MicrosoftDependencyInjectionExtensions.cs:21,9 C#
    0xE in Prism.Ioc.PrismServiceProviderFactory.CreateBuilder at /_/src/Prism.Container.Abstractions/PrismServiceProviderFactory.cs:41,9   C#
    0x11 in Microsoft.Maui.Hosting.MauiAppBuilder.<>c__DisplayClass12_0<Prism.Ioc. at /_/src/Core/src/Hosting/MauiAppBuilder.cs:135,5   C#
    0x23 in Microsoft.Maui.Hosting.MauiAppBuilder.Build at /_/src/Core/src/Hosting/MauiAppBuilder.cs:149,4  C#
>   0xF4 in ProjectBreatheApp.Maui.MauiProgram.CreateMauiApp at C:\Projects\MB\breathe.breatherm-app\ProjectBreatheApp.Maui\MauiProgram.cs:137,13   C#
    0x0 in ProjectBreatheApp.Maui.MainApplication.CreateMauiApp at C:\Projects\MB\breathe.breatherm-app\ProjectBreatheApp.Maui\Platforms\Android\MainApplication.cs:14,55   C#
    0xC in Microsoft.Maui.MauiApplication.OnCreate at /_/src/Core/src/Platform/Android/MauiApplication.cs:36,4  C#
    0x8 in Android.App.Application.n_OnCreate at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/obj/Release/net8.0/android-34/mcw/Android.App.Application.cs:1087,4    C#
    0x8 in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PP_V at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:22,5  C#

    DryIoc.ContainerException: 'code: Error.UnableToResolveUnknownService;
message: Unable to resolve Prism.Events.IEventAggregator as parameter "eventAggregator" (IsSingletonOrDependencyOfSingleton)
  in Singleton ProjectBreatheApp.Services.DataProviderService: ProjectBreatheApp.Interfaces.IDataProviderService as parameter "dataProviderService" FactoryId=830 (IsSingletonOrDependencyOfSingleton)
  in Singleton ProjectBreatheApp.Services.BreatheServices: ProjectBreatheApp.Interfaces.IBreatheServices as parameter "breatheServices" FactoryId=845 (IsSingletonOrDependencyOfSingleton)
  in resolution root ProjectBreatheApp.Maui.ViewModels.Settings.BreatheAccountNotConnectedViewModel FactoryId=1060
  from container without scope
 with Rules with {TrackingDisposableTransients, FuncAndLazyWithoutRegistration, SelectLastRegisteredFactory, UsedForValidation} and without {ThrowOnRegisteringDisposableTransient, ImplicitCheckForReuseMatchingScope, EagerCachingSingletonForFasterAccess} with TotalDependencyCountInLambdaToSplitBigObjectGraph=2147483647
 with FactorySelector=SelectLastRegisteredFactory
 with Made={FactoryMethod=ConstructorWithResolvableArguments}
Where no service registrations found
  and no dynamic registrations found in 1 of Rules.DynamicServiceProviders
  and nothing found in 0 of Rules.UnknownServiceResolvers'
dansiegel commented 1 month ago

A reproduction is required for all bug reports. The source of this issue is nearly guaranteed to be in your code.

munkii commented 1 month ago

I don't doubt it is my mistake I was just after some pointers or suggestions as to what might be causing that to happen.

dansiegel commented 1 month ago

without sample code it's impossible for me to guess what your mistake was