title: Custom UserManager always return null
body: <p>I am trying to create my own <code>UserManager</code> extending from the original, and when I do a search by email, the user is not found. But if I do a search from the context, if I find the user (see the <code>Get</code> method). To verify that it is really well implemented, I overwrote the <code>FindByEmailAsync</code> method and it is really being called, but I do not know why the user can not find it. Some help? Thank you!</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection servicesCollection)
  {
      servicesCollection.AddDbContext&lt;MyIndentityContext&gt;(currentOptions =&gt;
          currentOptions.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
  
      servicesCollection.AddIdentity&lt;ApplicationUser, ApplicationRole&gt;()
          .AddEntityFrameworkStores&lt;MyIndentityContext&gt;()
          .AddRoleStore&lt;ApplicationRoleStore&gt;()
          .AddUserStore&lt;ApplicationUserStore&gt;()
          .AddUserManager&lt;ApplicationUserManager&gt;()
          .AddRoleManager&lt;ApplicationRoleManager&gt;()
          .AddSignInManager&lt;ApplicationSignInManager&gt;()
          .AddDefaultTokenProviders();
  
          ...
  
          ...
  
          ...
  }
  
  public class MyIndentityContext : IdentityDbContext&lt;ApplicationUser, ApplicationRole, string&gt;
  {
      private readonly IConfiguration _configuration;
  
      private readonly IHttpContextAccessor _httpContextAccessor;
  
      public MyIndentityContext(DbContextOptions dbContextOptions, IHttpContextAccessor httpContextAccessor,
          IConfiguration configuration)
          : base(dbContextOptions)
      {
          _configuration = configuration;
          _httpContextAccessor = httpContextAccessor;
      }
  
      protected override void OnModelCreating(ModelBuilder modelBuilder)
      {
          base.OnModelCreating(modelBuilder);
  
          modelBuilder.HasDefaultSchema("Sample.API");
      }
  
  }
  
  public class ApplicationRoleManager : RoleManager&lt;ApplicationRole&gt;
  {
      public ApplicationRoleManager(IRoleStore&lt;ApplicationRole&gt; roleStore,
          IEnumerable&lt;IRoleValidator&lt;ApplicationRole&gt;&gt; roleValidators, ILookupNormalizer keyNormalizer,
          IdentityErrorDescriber errors, ILogger&lt;ApplicationRoleManager&gt; logger) : base(roleStore,
          roleValidators,
          keyNormalizer, errors, logger)
      {
      }
  }
  
  public class ApplicationSignInManager : SignInManager&lt;ApplicationUser&gt;
  {
      public ApplicationSignInManager(UserManager&lt;ApplicationUser&gt; userManager, IHttpContextAccessor contextAccessor,
          IUserClaimsPrincipalFactory&lt;ApplicationUser&gt; claimsFactory, IOptions&lt;IdentityOptions&gt; optionsAccessor,
          ILogger&lt;ApplicationSignInManager&gt; logger, IAuthenticationSchemeProvider schemes) : base(userManager,
          contextAccessor, claimsFactory, optionsAccessor, logger, schemes)
      {
      }
  }
  
  public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
  {
      public ApplicationUserManager(IUserStore&lt;ApplicationUser&gt; userStore, IOptions&lt;IdentityOptions&gt; optionsAccessor,
          IPasswordHasher&lt;ApplicationUser&gt; passwordHasher,
          IEnumerable&lt;IUserValidator&lt;ApplicationUser&gt;&gt; userValidators,
          IEnumerable&lt;IPasswordValidator&lt;ApplicationUser&gt;&gt; passwordValidators, ILookupNormalizer keyNormalizer,
          IdentityErrorDescriber errors, IServiceProvider services, ILogger&lt;ApplicationUserManager&gt; logger) :
          base(userStore, optionsAccessor, passwordHasher, userValidators, passwordValidators, keyNormalizer, errors,
              services, logger)
      { }
  
      // Custom implementation to check if you are really calling the method
      public override Task&lt;ApplicationUser&gt; FindByEmailAsync(string email)
      {
          return Task.Run(() =&gt; new ApplicationUser
          {
              UserName = "A_NAME"
          });
      }
  }
  
  public class ApplicationRoleStore : RoleStore&lt;ApplicationRole, MyIndentityContext&gt;
  {
      public ApplicationRoleStore(MyIndentityContext dbContext, IdentityErrorDescriber identityErrorDescriber)
          : base(dbContext, identityErrorDescriber)
      {}
  }
  
  public class ApplicationUserStore : UserStore&lt;ApplicationUser, ApplicationRole, MyIndentityContext, string&gt;
  {
      public ApplicationUserStore(MyIndentityContext dbContext, IdentityErrorDescriber identityErrorDescriber)
          : base(dbContext, identityErrorDescriber)
      {}
  
  }
  
  public class ApplicationUser : IdentityUser {}
  
  public class ApplicationRole : IdentityRole
  {
      public ApplicationRole() { }
  
      public ApplicationRole(string roleName) : base(roleName) { }
  
      public ApplicationRole(string roleName, string roleDescription) : base(roleName)
      {
          Description = roleDescription;
      }
  
  }
  
  [Authorize]
  [ApiController]
  [Route("api/[controller]")]
  [EnableCors(CORS.AllowSpecificOrigins)]
  
  public class UserController : BaseController
  {
      private readonly ApplicationUserManager _applicationUserManager;
  
      public UserController(ApplicationUserManager applicationUserManager)
      {
          _applicationUserManager = applicationUserManager;
      }
  
       // GET: api/User/5
      [HttpGet("{id}")]
      public async Task&lt;UserDTO&gt; Get(int id)
      {
  
              var currentUser = await _applicationUserManager.FindByEmailAsync("example@example.com"); ==&gt; RETURN NULL!
  
              var otherUser = _indentityContext.Users.Where(x =&gt; x.Email == "example@example.com"); ==&gt; RETURN CORRECT USER!
  
              return currentUser;
  
      }
  
  }
  </code></pre>