AddRadzenComponents middleware doesn't load until after first page is rendered

I have a new Blazor WASM .NET 8 app that is showing a bizarre behavior. If launch the app and the first page I load requires the RadzenComponents services in the dependancy injection container (IOW, has a <RadzenComponents/> tag that relies on them), it throws an error "InvalidOperationException: Cannot provide a value for property 'dialogService' on type 'StrawberryShakeWASM.Client.Pages.AccountEdit'. There is no registered service of type 'Radzen.DialogService'." However, if I launch the app to a page that does not have the <RadzenComponents/> tag, and then go to a page that does, everything works as expected.

Experimentally, it appears that the builder.Services.AddRadzenComponents() call launches something asynchronous that doesn't complete before the first page load begins. This doesn't seem possible since the call is not asynchronous and the call is made before await builder.Build().RunAsync() is ever called to start the application.

Thoughts?

Hi @Greg_Wilson,

We haven't seen such a problem before. Registering services is never asynchronous so the problem is somewhere else.

What can cause "InvalidOperationException: Cannot provide a value for property 'dialogService' on type 'StrawberryShakeWASM.Client.Pages.AccountEdit'. There is no registered service of type 'Radzen.DialogService'." after the builder.Services.AddRadzenComponents() call has already been made that only happens if it is the first page rendered?

Because if "Registering services is never asynchronous" the error must be caused by something other that the services not being registered.

I haven't seen such an error before (provided that there is AddRadzenComponents). Are you sure you have it in the right place? .NET 8 applications have two Program.cs files - one for WASM and one for the SSR (server). With SSR enabled the application is still rendered twice so any services needed have to be registered in both locations.

Bingo. This was the issue. However, it is weirder than that. May application does not even have SSR rendering enabled, only WASM rendering. (Following the MS guidance here to set my app as WASM-only and render mode to be InteractiveWebAssembly)
Regardless, adding these services on the server stops the errors.

It probably has prerendering enabled though (it gets really confusing I know :))

Thanks! I found out how to turn this off here

I'll need to do some further testing to see if prerendering provides enough benefits to make configuring the server worth it. This is a really poorly documented thing that apparently interactivewebassembly render mode still does server rendering for pre-rendering, but I appreciate you pointing this out!