I have a WPF Prism application with Unity container. I would like to add the Serilog logging service. So I override RegisterTypes as follows:
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterServices(serviceCollection =>
serviceCollection.AddLogging(logbuilder => logbuilder.AddSerilog(dispose: true)));
}
I have following Nuget packages installed:
- Prism.Core
- Prism.Unity
- Prism.Unity.Extensions
- Prism.Wpf
When resolving het MainWindow type from the container I get the error InvalidOperationException: No public constructor is available for type System.IServiceProvider
Related information:
- working solution for Prism Xamarin Forms and Dryloc or Unity: DryIoc and IServiceProvider on Prism for Xamarin.Forms (DryIoc.Microsoft.DependencyInjection)
- https://github.com/augustoproiete/prism-logging-serilog/issues/3
- .net5.0 PRISM WPF application, how to use Microsoft.Exensions.Logging with Serilog as provider?
I can get it to work when I follow the implementation documented in https://www.andicode.com/prism/wpf/logging/2021/05/21/Logging-In-Prism.html but this is not the same methodology as for Prism Xamarin Forms and Dryloc or Unity.
What is the reason for the difference between WPF and Xamarin Forms?