find and solve || findandsolve.com
Please wait.....

Add all the required services by calling IServiceCollection.AddAuthorization inside the call to ConfigureServices

Add all the required services by calling IServiceCollection.AddAuthorization inside the call to ConfigureServices

System.InvalidOperationException HResult=0x80131509 Message=Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddAuthorization' inside the call to 'ConfigureServices(...)' in the application startup code. Source=Microsoft.AspNetCore.Authorization.Policy StackTrace: at Microsoft.AspNetCore.Builder.AuthorizationAppBuilderExtensions.VerifyServicesRegistered(IApplicationBuilder app) at Microsoft.AspNetCore.Builder.AuthorizationAppBuilderExtensions.UseAuthorization(IApplicationBuilder app) at AMS.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in C:\Users\User-Pc\Desktop\AMS\AMS\Startup.cs:line 67 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.b__0(IApplicationBuilder builder) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.b__1(IApplicationBuilder app) at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.b__0(IApplicationBuilder app) at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.b__0(IApplicationBuilder app) at Microsoft.AspNetCore.Hosting.GenericWebHostService.d__31.MoveNext()

Answer

Option 1.

Add this in your service as given below

  public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();
            services.AddIdentity<IdentityUser, IdentityRole>(options =>
            {
                options.Password.RequiredLength = 1;
                options.Password.RequireLowercase = false;
                options.Password.RequireUppercase = false;
                options.Password.RequireNonAlphanumeric = false;
                options.Password.RequireDigit = false;
            })
             .AddEntityFrameworkStores<AMSContext>()
             .AddDefaultTokenProviders();
        }

Hope this will working fine in your project.

Option 2.

The exception message clearly indicates that your should invoke services.AddHealthChecks() inside ConfigureServices(IServiceCollection services)

void ConfigureServices(IServiceCollection services) {
    // something here
    services.AddHealthChecks();
    //something here
}

For more details: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/health-checks?view=aspnetcore-5.0


Comments



Report Response