title: IServiceCollection does not contain a definition for AddDefaultIdentity
body: <p>Any idea why am I getting this error?   Error Message --&gt; &quot;IServiceCollection does not contain a definition for AddDefaultIdentity&quot;</p>
  <pre class="lang-cs prettyprint-override"><code>public class Program
  {
      public async static void Main(string[] args)
      {
          await Host.CreateDefaultBuilder(args)
          .ConfigureWebHostDefaults(webBuilder =&gt; {
             webBuilder.UseContentRoot(Directory.GetCurrentDirectory());
             webBuilder.UseKestrel();
             webBuilder.UseAzureAppServices();
             webBuilder.UseStartup&lt;Startup&gt;();
         })
        .Build()
        .RunAsync();
     }
  }
  
  public class Startup
  {
      public Startup(IConfiguration configuration, IHostEnvironment hostEnvironment)
      {
          Configuration = configuration;
          HostEnvironment = hostEnvironment;
      }
  
      public IConfiguration Configuration { get; }
      protected IApplicationBuilder ApplicationBuilder { get; private set; }
      public IHostEnvironment HostEnvironment { get; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          //           services.AddRazorPages();
  
          services.AddDefaultIdentity&lt;ApplicationUser&gt;()  // &quot;ApplicationUser&quot; is named incorrectly, it should be &quot;IdentityUser&quot; instead, as per Microsoft documentation.
              .AddRoles&lt;IdentityRole&lt;Guid&gt;&gt;()
              .AddEntityFrameworkStores&lt;ApplicationContext, Guid&gt;()  // FYI - AddEntityFrameworkStores() deal with role that derives from IdentityRole, as per documentation.
              //.AddDefaultUI()
              .AddDefaultTokenProviders();
  
          // [ Old version #1 - replacement ]
          services.ConfigureApplicationCookie(options =&gt;
          {
              options.LoginPath = new PathString(&quot;/Home/Index&quot;);
              options.SlidingExpiration = true;
              options.ExpireTimeSpan = TimeSpan.FromMinutes(this.Configuration.GetValue&lt;int?&gt;(&quot;Authentication:SlidingExpirationTime&quot;).Value);
              options.AccessDeniedPath = new PathString(&quot;/Home/AccessDenied&quot;);
          });
  
          // [ Old version #2 - replacement ]
          services.Configure&lt;IdentityOptions&gt;(options =&gt;
          {
              options.Password.RequireUppercase = false;
              options.Password.RequireLowercase = false;
              options.Password.RequireNonAlphanumeric = false;
              options.Password.RequireDigit = false;
              options.Password.RequiredLength = 7;
          });
  
          services.AddMvc();
          services.AddSession();
  
          //services.Configure&lt;AuthorizationOptions&gt;(options =&gt;
          //{
          //});
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
      {
          if (env.IsDevelopment())
          {
             app.UseDeveloperExceptionPage();
          }
          else
          {
              app.UseExceptionHandler(&quot;/Error&quot;);
          }
  
          app.UseHttpsRedirection();
          app.UseStaticFiles();
          app.UseRouting();
          app.UseAuthorization();
          app.UseEndpoints(endpoints =&gt;
          {
              endpoints.MapRazorPages();
          });
  
          // Config Exception.
          if (env.IsDevelopment())
              app.UseDeveloperExceptionPage();
          else
              app.UseExceptionHandler(&quot;/Home/ErrorPage.html&quot;);
          
          app.UseStaticFiles(); // Note, we are not authenticating for static files if this is before them
          app.UseSession();
          app.UseAuthentication();
  
          // MVC.
          // app.UseMvc(routes =&gt; routes.MapRoute(&quot;default&quot;, &quot;{controller=Home}/{action=Index}/{id?}&quot;));
      }
  }
  
  public class ApplicationUser : IdentityUser&lt;Guid&gt;, IUser
  {
  }
  
  public interface IUser
  {
  }
  
  public class ApplicationContext : IdentityDbContext&lt;ApplicationUser, IdentityRole&lt;Guid&gt;, Guid&gt;
  {
      public ApplicationContext(DbContextOptions&lt;ApplicationContext&gt; options)
          : base(options)
      {
      }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
      }
  }
  </code></pre>
  <pre class="lang-xml prettyprint-override"><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk.Web&quot;&gt;
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;netcoreapp3.1&lt;/TargetFramework&gt;
    &lt;/PropertyGroup&gt;
  
    &lt;ItemGroup&gt;
      &lt;PackageReference Include=&quot;Microsoft.ApplicationInsights.AspNetCore&quot; Version=&quot;2.0.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.DataProtection&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.DataProtection.AzureStorage&quot; Version=&quot;1.0.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Diagnostics&quot; Version=&quot;1.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Mvc.Formatters.Xml&quot; Version=&quot;1.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Session&quot; Version=&quot;1.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.StaticFiles&quot; Version=&quot;1.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Configuration.Binder&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Configuration.CommandLine&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackgaeReference Include=&quot;Microsoft.Extensions.Hosting&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Logging.Console&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.SqlServer&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.EntityFrameworkCore.InMemory&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Identity&quot; Version=&quot;2.2.0&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Identity.EntityFrameworkCore&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Mvc&quot; Version=&quot;1.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.Extensions.Configuration.Json&quot; Version=&quot;3.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Mvc&quot; Version=&quot;1.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Mvc.Formatters.Json&quot; Version=&quot;1.1.3&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Server.IISIntegration&quot; Version=&quot;1.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.Server.Kestrel&quot; Version=&quot;1.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.StaticFiles&quot; Version=&quot;1.1.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Newtonsoft.Json&quot; Version=&quot;12.0.2&quot; /&gt;
      &lt;PackageReference Include=&quot;Microsoft.AspNetCore.AzureAppServicesIntegration&quot; Version=&quot;1.0.2&quot; /&gt;
    &lt;/ItemGroup&gt;
  &lt;/Project&gt;
  </code></pre>
  <p>-- Edited - New Update Below. -------------------------------------------------------</p>
  <p>Ok, that help by adding &quot;Microsoft.AspNetCore.Identity.UI&quot; NuGet package.   Now I have run into another error.  :-/   I can't make sense of this one.</p>
  <pre><code>services.AddDefaultIdentity&lt;ApplicationUser&gt;() 
  .AddRoles&lt;IdentityRole&lt;Guid&gt;&gt;()
  .AddEntityFrameworkStores&lt;ApplicationContext, Guid&gt;() 
  .AddDefaultTokenProviders();
  </code></pre>
  <p>The error on the first line is gone now.  But now new error on 3rd line here, &quot;AddEntityFrameworkStore&lt;ApplicationContext, Guid&gt;()&quot;.   The error message is --&gt; &quot;IdentityBuilder&quot; does not contain a definition for &quot;AddEntityFrameworkStores&quot; &amp; no accessible extension method &quot;AddEntityFrameworkStores&quot; accepting a first argument of type &quot;IdentityBuilder&quot; could be found (are you mising a using directive or an assembly reference?).</p>
  <p>Not even sure what NuGet package does this &quot;AddEntityFrameworkStores&quot; come from &amp; what have changed from version 1 to 3.1 either.</p>