Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I try
Dim msgBoxService As IMsgBoxService = Ioc.[Default].GetService(Of IMsgBoxService)()
msgBoxService.Show("TEST")

I get error "The service provider has not been configured yet"
27.01.2022 13:31:20; System.InvalidOperationException: The service provider has not been configured yet
   bei Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.GetService[T]() in /_/Microsoft.Toolkit.Mvvm/DependencyInjection/Ioc.cs:Zeile 90.
   bei WinformHostsRibbonWPF_MVVM_Toolkit.TextDataViewModel..ctor() in E:\Daten\VSCommunity\Projects\VS2022_Articles_CP\WinformHostsRibbonWPF_MVVM_Toolkit\ViewModels\TextDataViewModel.vb:Zeile 47.


What I have tried:

When I try
Ioc.[Default].ConfigureServices(New ServiceCollection().AddSingleton(Of IMsgBoxService, MsgBoxService)().AddSingleton(Of IMsgBoxService)(New MsgBoxService()).BuildServiceProvider())
Dim msgBoxService As IMsgBoxService = Ioc.[Default].GetService(Of IMsgBoxService)()
msgBoxService.Show("TEST")

Then the error is "The default service provider has already been configured"
27.01.2022 13:34:27; System.InvalidOperationException: The default service provider has already been configured
   bei Microsoft.Toolkit.Mvvm.DependencyInjection.Ioc.ConfigureServices(IServiceProvider serviceProvider) in /_/Microsoft.Toolkit.Mvvm/DependencyInjection/Ioc.cs:Zeile 139.
   bei WinformHostsRibbonWPF_MVVM_Toolkit.TextDataViewModel..ctor() in E:\Daten\VSCommunity\Projects\VS2022_Articles_CP\WinformHostsRibbonWPF_MVVM_Toolkit\ViewModels\TextDataViewModel.vb:Zeile 46.
Posted
Updated 27-Jan-22 2:30am

1 solution

From the error, it looks like you're creating multiple instances of the TextDataViewModel class, which means you're trying to call ConfigureServices multiple times.

Move the DI configuration to the Application constructor, so that it only runs once during the lifetime of the process.
 
Share this answer
 
Comments
Jo_vb.net 27-Jan-22 8:38am    
Thank you very much.
That was the case, now it works fine.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900