title: UserManager.FindAsync always returns null
body: <p>I have the following Login action on a and the UserManager.FindAsync always returns null. I am trying to seed the users with the code shown at the bottom.</p>
  
  <p>Can anyone help please?</p>
  
  <pre><code>    public async Task&lt;ActionResult&gt; Login(LoginViewModel model, string returnUrl)
      {
          if (ModelState.IsValid)
          {
              var user = await UserManager.FindAsync(model.Email, model.Password);
              if (user != null)
              {
                  await SignInAsync(user, model.RememberMe);
                  return RedirectToLocal(returnUrl);
              }
              else
              {
                  ModelState.AddModelError("", "Invalid username or password.");
              }
          }
  
          // If we got this far, something failed, redisplay form
          return View(model);
      }
  </code></pre>
  
  <p>I have the following bit of code for in the Configuration.cs under Migrations. What it does is seed a user that I am trying to log in with the code above.</p>
  
  <pre><code>    protected override void Seed(Temps.Models.ApplicationDbContext context)
      {
          if (!context.Roles.Any(r =&gt; r.Name == "Consultant"))
          {
              var store = new RoleStore&lt;IdentityRole&gt;(context);
              var manager = new RoleManager&lt;IdentityRole&gt;(store);
              var role = new IdentityRole { Name = "Consultant" };
  
              manager.Create(role);
          }
  
          if (!context.Users.Any(u =&gt; u.UserName == "Consultant"))
          {
              var store = new UserStore&lt;ApplicationUser&gt;(context);
              var manager = new UserManager&lt;ApplicationUser&gt;(store);
              var user = new ApplicationUser
              {
                  UserName = "Consultant",
                  Email = "consultant@temps-ltd.co.uk"
              };
  
              manager.Create(user, "password");
              manager.AddToRole(user.Id, "Consultant");
          }
  </code></pre>
  
  <hr>
  
  <p><em>UPDATE</em></p>
  
  <p>After implementing Anthony's changes I get the following error for the seed code below, any ideas?</p>
  
  <pre><code>PM&gt; Update-database
    Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
    No pending explicit migrations.
    Running Seed method.
    System.InvalidOperationException: UserId not found.
       at Microsoft.AspNet.Identity.UserManager2.&lt;AddToRoleAsync&gt;d__83.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at Microsoft.AspNet.Identity.AsyncHelper.RunSync[TResult](Func1 func)
       at Microsoft.AspNet.Identity.UserManagerExtensions.AddToRole[TUser,TKey](UserManager2 manager, TKey userId, String role)
       at Temps.Migrations.Configuration.Seed(ApplicationDbContext context) in c:\Work\@wandc\Temps\trunk\src\Temps\Migrations\Configuration.cs:line 67
       at System.Data.Entity.Migrations.DbMigrationsConfiguration1.OnSeed(DbContext context)
       at System.Data.Entity.Migrations.DbMigrator.SeedDatabase()
       at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.SeedDatabase()
       at System.Data.Entity.Migrations.DbMigrator.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId)
       at System.Data.Entity.Migrations.Infrastructure.MigratorLoggingDecorator.Upgrade(IEnumerable1 pendingMigrations, String targetMigrationId, String lastMigrationId)
       at System.Data.Entity.Migrations.DbMigrator.UpdateInternal(String targetMigration)
       at System.Data.Entity.Migrations.DbMigrator.&lt;&gt;c__DisplayClassc.&lt;Update&gt;b__b()
       at System.Data.Entity.Migrations.DbMigrator.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.EnsureDatabaseExists(Action mustSucceedToKeepDatabase)
       at System.Data.Entity.Migrations.DbMigrator.Update(String targetMigration)
       at System.Data.Entity.Migrations.Infrastructure.MigratorBase.Update(String targetMigration)
       at System.Data.Entity.Migrations.Design.ToolingFacade.UpdateRunner.Run()
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)
       at System.Data.Entity.Migrations.Design.ToolingFacade.Update(String targetMigration, Boolean force)
       at System.Data.Entity.Migrations.UpdateDatabaseCommand.&lt;&gt;c__DisplayClass2.&lt;.ctor&gt;b__0()
       at System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action command)
    UserId not found.
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>        if (!context.Users.Any(u =&gt; u.UserName == "admin@temps-ltd.co.uk"))
          {
              string emailAddress = "admin@temps-ltd.co.uk";
  
              var store = new UserStore&lt;ApplicationUser&gt;(context);
              var manager = new UserManager&lt;ApplicationUser&gt;(store);
              var user = new ApplicationUser()
              {
                  UserName = emailAddress,
                  Email = emailAddress,
                  FirstName = "Admin",
                  LastName = "Admin",
                  PasswordHint = password
              };
  
              manager.Create(user, password);                
              manager.AddToRole(user.Id, "Admin");
          }
  </code></pre>