DuendeSoftware / Support

Support for Duende Software products
20 stars 0 forks source link

Cannot launch BlazorServer sample #1249

Closed maxmantz closed 3 months ago

maxmantz commented 3 months ago

Which version of Duende.AccessTokenManagement are you using? 3.0.0-preview.1

Which version of .NET are you using? net8.0

Describe the bug While trying to run the BlazorServer app from the samples directory, the startup process crashes with the following exception:

System.AggregateException
  HResult=0x80131500
  Message=Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler Lifetime: Scoped ImplementationType: Duende.AccessTokenManagement.OpenIdConnect.ServicesAccessorCircuitHandler': A suitable constructor for type 'Duende.AccessTokenManagement.OpenIdConnect.ServicesAccessorCircuitHandler' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.)
  Source=Microsoft.Extensions.DependencyInjection
  StackTrace:
   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(ICollection`1 serviceDescriptors, ServiceProviderOptions options)
   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
   at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
   at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
   at BlazorServer.HostingExtensions.ConfigureServices(WebApplicationBuilder builder) in C:\Users\maxim\OneDrive\Dokumente\Duende.AccessTokenManagement\samples\BlazorServer\HostingExtensions.cs:line 72
   at Program.<Main>$(String[] args) in C:\Users\maxim\OneDrive\Dokumente\Duende.AccessTokenManagement\samples\BlazorServer\Program.cs:line 22

  This exception was originally thrown at this call stack:
    [External Code]

Inner Exception 1:
InvalidOperationException: Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler Lifetime: Scoped ImplementationType: Duende.AccessTokenManagement.OpenIdConnect.ServicesAccessorCircuitHandler': A suitable constructor for type 'Duende.AccessTokenManagement.OpenIdConnect.ServicesAccessorCircuitHandler' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

Inner Exception 2:
InvalidOperationException: A suitable constructor for type 'Duende.AccessTokenManagement.OpenIdConnect.ServicesAccessorCircuitHandler' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

To Reproduce Just run the BlazorServer app from the samples folder in the main branch.

Expected behavior

The services are registered correctly and the app starts without issues.

Log output/exception with stacktrace

see above

Additional context

Looking at the source code and exception, the affected ServicesAccessorCircuitHandler depends on a scoped CircuitServicesAccessor. I've tried to add builder.Services.AddScoped<CircuitServicesAccessor>() to the startup project but to no avail. However, making the service's constructor public instead of private seems to solve the issue.

maxmantz commented 3 months ago

Closing this as the merge of my PR fixed the issue. Thanks a lot 👍

josephdecock commented 3 months ago

Thanks for trying out the previews and catching this, and for the PR!