It is said that you need to add this line into ConfigureServices in the Server project when using Server Prerender:
services.AddSingleton<LazyAssemblyLoader>();
This throws an error, because in a Server project, IJsRuntime has a scoped lifetime and the LazyAssemblyLoader tries to dependency inject it throws this error:
AggregateException: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Components.WebAssembly.Services.LazyAssemblyLoader Lifetime: Singleton ImplementationType: Microsoft.AspNetCore.Components.WebAssembly.Services.LazyAssemblyLoader': Cannot consume scoped service 'Microsoft.JSInterop.IJSRuntime' from singleton 'Microsoft.AspNetCore.Components.WebAssembly.Services.LazyAssemblyLoader'.)
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@captainsafia ... The guidance for the service registration is in the following section ...
https://docs.microsoft.com/aspnet/core/blazor/webassembly-lazy-load-assemblies?view=aspnetcore-5.0#assembly-load-logic-in-onnavigateasync
The framework's lazy loading implementation supports lazy loading with prerendering in a hosted Blazor solution. During prerendering, all assemblies, including those marked for lazy loading, are assumed to be loaded. Manually register
LazyAssemblyLoaderin the Server project'sStartup.ConfigureServicesmethod (Startup.cs):services.AddSingleton<LazyAssemblyLoader>();
@guardrex Argh! Yeah, this should be AddScoped. I think you might've actually had it set to that at first before I nudged you to the wrong solution.
Most helpful comment
@guardrex Argh! Yeah, this should be
AddScoped. I think you might've actually had it set to that at first before I nudged you to the wrong solution.