An unhandled exception of type 'System.AggregateException' occurred in Microsoft.Extensions.DependencyInjection.dll:


I migrated a core project from version 2.2 to 3.1. I have added all the dependencies and docker related components. It is compiling fine but on running the project I am getting the below mentioned error:

Exception thrown: 'System.AggregateException' in Microsoft.Extensions.DependencyInjection.dll An unhandled exception of type 'System.AggregateException' occurred in Microsoft.Extensions.DependencyInjection.dll: 'Some services are not able to be constructed' Stack trace: at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable1 serviceDescriptors, ServiceProviderOptions options) at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options) at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder) at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter1.CreateServiceProvider(Object containerBuilder) at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider() at Microsoft.Extensions.Hosting.HostBuilder.Build() at Sample.API.Program.Main(String[] args) in /src/QueryStack/Sample.API/Program.cs:line 20 The program 'kubectl.exe' has exited with code -1 (0xffffffff).

Here goes my code:


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace Sample.API
    public class Program
        public static void Main(string[] args)
            // Use the W3C Trace Context format to propagate distributed trace identifiers.
            // See
            Activity.DefaultIdFormat = ActivityIdFormat.W3C;

        public static IHostBuilder CreateHostBuilder(string[] args) => 
            .ConfigureWebHostDefaults(webBuilder =>
                webBuilder.UseKestrel(options => options.AddServerHeader = false);


using Sample.API.Constants;
using Sample.API.Extensions;
using Sample.API.GraphQL;
using Sample.API.Middleware;
using Boxed.AspNetCore;
using GraphQL.Server;
using GraphQL.Server.Ui.Playground;
using GraphQL.Server.Ui.Voyager;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Sample.API
    public class Startup
        private readonly IConfiguration configuration;
        private readonly IWebHostEnvironment webHostEnvironment;
        /// <summary>
        /// Initializes a new instance of the <see cref = "Startup"/> class.
        /// </summary>
        /// <param name = "configuration">The application configuration, where key value pair settings are stored. See
        /// <param name = "webHostEnvironment">The environment the application is running under. This can be Development,
        /// Staging or Production by default. See</param>
        public Startup(IConfiguration configuration, IWebHostEnvironment webHostEnvironment)
            this.configuration = configuration;
            this.webHostEnvironment = webHostEnvironment;

        /// <summary>
        /// Configures the services to add to the ASP.NET Core Injection of Control (IoC) container. This method gets
        /// called by the ASP.NET runtime. See
        /// </summary>
        public virtual void ConfigureServices(IServiceCollection services) => 
            .AddCustomGraphQL(configuration, webHostEnvironment)

        /// <summary>
        /// Configures the application and HTTP request pipeline. Configure is called after ConfigureServices is
        /// called by the ASP.NET runtime.
        /// </summary>
        public virtual void Configure(IApplicationBuilder application) =>
                    x => x.UseServerTiming())
                    x => x.UseHsts())
                    x => x.UseDeveloperExceptionPage())
                    builder =>
                            .MapHealthChecks("/status/self", new HealthCheckOptions() { Predicate = _ => false })
                // Use the GraphQL subscriptions in the specified schema and make them available at /graphql.
                // Use the specified GraphQL schema and make them available at /graphql.
                    x => x
                        // Add the GraphQL Playground UI to try out the GraphQL API at /.
                        .UseGraphQLPlayground(new GraphQLPlaygroundOptions() { Path = "/" })
                        // Add the GraphQL Voyager UI to let you navigate your GraphQL API as a spider graph at /voyager.
                        .UseGraphQLVoyager(new GraphQLVoyagerOptions() { Path = "/voyager" }));

I followed the guidelines of Templates mentioned at:

Based on the above I created a POC which works fine but not the above mentioned code.

Can anyone help me to fix this issue by providing their guidance

asked on Stack Overflow Dec 24, 2019 by santosh kumar patro • edited Dec 24, 2019 by Nkosi

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0