Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled exception. System.InvalidOperationException: This service descriptor is keyed. Your service provider may not support keyed services. #326

Open
PawelTroka opened this issue Jun 17, 2024 · 1 comment

Comments

@PawelTroka
Copy link

Code:

public class Program
{
    public static void Main(string[] args)
    {
        CreateHostBuilder(args).Build().Run();
    }

    public static IHostBuilder CreateHostBuilder(string[] args)
    {
        return Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); })
            .UseServiceContext();
    }
}

Stacktrace:

Unhandled exception. System.InvalidOperationException: This service descriptor is keyed. Your service provider may not support keyed services.
   at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ThrowKeyedDescriptor()
   at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.get_ImplementationType()
   at AspectCore.Extensions.DependencyInjection.ServiceCollectionToServiceContextExtensions.Replace(ServiceDescriptor descriptor)
   at System.Linq.Enumerable.SelectIListIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetLast[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.LastOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at AspectCore.DependencyInjection.ServiceContext..ctor(IEnumerable`1 services, IAspectConfiguration aspectConfiguration)
   at AspectCore.DependencyInjection.ServiceContext..ctor(IEnumerable`1 services)
   at AspectCore.Extensions.DependencyInjection.ServiceCollectionToServiceContextExtensions.ToServiceContext(IServiceCollection services)
   at AspectCore.Extensions.DependencyInjection.ServiceContextProviderFactory.CreateBuilder(IServiceCollection services)
   at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter`1.CreateBuilder(IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.InitializeServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Neutral.Rfq.Api.Program.Main(String[] args) in Program.cs:line 11
@fivecky
Copy link

fivecky commented Jun 30, 2024

I'm having the same problem.

due to using the AddKeyedXXXService() of Microsoft.Extensions.DependencyInjection 8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants