title: Unable to find the required services.Add the required services by calling 'IServiceCollection.AddControllers'inside the call to 'ConfigureServices()'
body: <p>I was following a tutorial of ASP.NET Core MVC web app and then this error generated I tried approximately everything that I know . The <code>MapDefaultControllerRoute();</code>is also not working . I also tried shifting from dotnet 6.0 to dotnet core 3.1 but still no progress. Below I'm attaching the error generated and the files:</p>
  <p>Error Generated:</p>
  <pre><code>An error occurred while starting the application.
  InvalidOperationException: Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddControllers' inside the call to 'ConfigureServices(...)' in the application startup code.
  Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.EnsureControllerServices(IEndpointRouteBuilder endpoints)
  
  InvalidOperationException: Unable to find the required services. Please add all the required services by calling 'IServiceCollection.AddControllers' inside the call to 'ConfigureServices(...)' in the application startup code.
  Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.EnsureControllerServices(IEndpointRouteBuilder endpoints)
  Microsoft.AspNetCore.Builder.ControllerEndpointRouteBuilderExtensions.MapControllerRoute(IEndpointRouteBuilder endpoints, string name, string pattern, object defaults, object constraints, object dataTokens)
  ConsoleApp3.Startup+&lt;&gt;c.&lt;Configure&gt;b__1_0(IEndpointRouteBuilder endpoints) in Startup.cs
  +
                  endpoints.MapControllerRoute(
  Microsoft.AspNetCore.Builder.EndpointRoutingApplicationBuilderExtensions.UseEndpoints(IApplicationBuilder builder, Action&lt;IEndpointRouteBuilder&gt; configure)
  ConsoleApp3.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in Startup.cs
  +
              app.UseEndpoints(endpoints =&gt;
  System.RuntimeMethodHandle.InvokeMethod(object target, object[] arguments, Signature sig, bool constructor, bool wrapExceptions)
  System.Reflection.RuntimeMethodInfo.Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
  Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(object instance, IApplicationBuilder builder)
  Microsoft.AspNetCore.Hosting.ConfigureBuilder+&lt;&gt;c__DisplayClass4_0.&lt;Build&gt;b__0(IApplicationBuilder builder)
  Microsoft.AspNetCore.Hosting.GenericWebHostBuilder+&lt;&gt;c__DisplayClass13_0.&lt;UseStartup&gt;b__2(IApplicationBuilder app)
  Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter+&lt;&gt;c__DisplayClass2_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
  Microsoft.AspNetCore.HostFilteringStartupFilter+&lt;&gt;c__DisplayClass0_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
  Microsoft.WebTools.BrowserLink.Net.HostingStartup+&lt;&gt;c__DisplayClass1_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
  Microsoft.AspNetCore.Watch.BrowserRefresh.HostingStartup+&lt;&gt;c__DisplayClass1_0.&lt;Configure&gt;b__0(IApplicationBuilder app)
  Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
  Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
  Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
  Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
  Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.Run(IHost host)
  ConsoleApp3.Program.Main(string[] args) in program.cs
  +
              CreateHostBuilder(args).Build().Run();
  </code></pre>
  <p>startup.cs file:</p>
  <pre><code>using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.Http;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  
  namespace ConsoleApp3
  {
      public class Startup
      {
          public void ConfigurationServices(IServiceCollection services)
          {
              services.AddControllersWithViews();
          }
          public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
          {
              if (env.IsDevelopment())
              {
                  app.UseDeveloperExceptionPage();
              }
  
              app.UseRouting();
  
              app.UseEndpoints(endpoints =&gt;
              {
                  endpoints.MapControllerRoute(
                      name: &quot;default&quot;,
                      pattern: &quot;{controller=Home}/{action=Index}/{id?}&quot;);
              });
  
          }
      }
  }
  </code></pre>
  <p>Program.cs :</p>
  <pre><code>using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.Hosting;
  using System;
  
  namespace ConsoleApp3
  {
      class Program
      {
          static void Main(string[] args)
          {
  
              CreateHostBuilder(args).Build().Run();
          }
          public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
  
              Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =&gt;
              {
                  webBuilder.UseStartup&lt;Startup&gt;();
              });
  
      }
  }
  </code></pre>
  <p>HomeController.cs file:</p>
  <pre><code>
  using Microsoft.AspNetCore.Mvc;
  
  namespace WebApplication1.Controllers
  {
      public class HomeController: Controller
      {
          public string Index()
          {
              return &quot;Web Master&quot;;
          }
      }
  }
  </code></pre>