title: AspNet.Identity Custom User and Custom Role should be simple; what am I missing?
body: <p>Using examples from <a href="http://www.asp.net/identity" rel="nofollow noreferrer">http://www.asp.net/identity</a> I've gotten this far.  The <code>RoleManager</code> works flawlessly and I treat the <code>UserManager</code> the same. I think everything is correct, but I can't seem to new up a <code>UserManager</code> correctly in a controller.  What is wrong?  At one point, I was successfully getting the <code>UserManager</code> to work but was getting an <code>EntityValidationError</code> saying &quot;Id is required&quot; when creating a new user with <code>UserManager.Create(user, password);</code> as posted in this question <a href="https://stackoverflow.com/questions/22698744/usermanager-createuser-password-thowing-entityvalidationerror-saying-id-is-re">UserManager.Create(user, password) thowing EntityValidationError saying Id is required?</a></p>
  <p>So after some time of hit and miss, I've created everything like the following but am getting a compile-time error on <code>new ApplicationUserManager(new ApplicationUserStore(new MyAppDb()))</code> saying:</p>
  <blockquote>
  <p>The best overloaded method match for MyApp.Models.ApplicationUserManager.ApplicationUserManager(Microsoft.AspNet.Identity.IUserStore&lt;MyApp.Models.ApplicationUser&gt;)'
  has some invalid arguments&quot;</p>
  </blockquote>
  <p>when trying to create the <code>UserManager</code> in my controller:</p>
  <p>Here is the controller:</p>
  <pre><code>namespace MyApp.Controllers
  {
      [Authorize]
      public class AccountController : BaseController
      {
          public AccountController()
              : this(new ApplicationUserManager(new ApplicationUserStore(new MyAppDb())))
          {
          }
  
          public AccountController(ApplicationUserManager userManager)
          {
              UserManager = userManager;
          }
  
          public ApplicationUserManager UserManager { get; private set; }
  ...
  }
  </code></pre>
  <p>Here is the model:</p>
  <pre><code>namespace MyApp.Models
  {
      public class ApplicationUser : IdentityUser&lt;string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim&gt;
      {
          [Required]
          [StringLength(50)]
          public string FirstName { get; set; }
  
          [Required]
          [StringLength(50)]
          public string LastName { get; set; }
  
  
          public async Task&lt;ClaimsIdentity&gt; GenerateUserIdentityAsync(UserManager&lt;ApplicationUser&gt; manager)
          {
              // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
              var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
              // Add custom user claims here
              return userIdentity;
          }
      }
  
      public class ApplicationUserLogin : IdentityUserLogin&lt;string&gt;
      {
      }
  
      public class ApplicationUserClaim : IdentityUserClaim&lt;string&gt;
      {
      }
  
      public class ApplicationUserRole : IdentityUserRole&lt;string&gt;
      {
      }
  
      public class ApplicationRole : IdentityRole&lt;string, ApplicationUserRole&gt;
      {
          [Required]
          [StringLength(50)]
          public string ProperName { get; set; }
  
          [Required]
          public string Description { get; set; }
      }
  
  
      public class MyAppDb : IdentityDbContext&lt;ApplicationUser, ApplicationRole, string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim&gt;
      {
          public MyAppDb()
              : base(&quot;MyAppDb&quot;)
          {
          }
      }
  
  
      public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
      {
          public ApplicationUserManager(IUserStore&lt;ApplicationUser&gt; store)
              : base(store)
          {
              this.PasswordValidator = (IIdentityValidator&lt;string&gt;)new MinimumLengthValidator(8);
              this.UserValidator = new UserValidator&lt;ApplicationUser&gt;(this) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true };
          }
  
      }
  
      public class ApplicationUserStore : UserStore&lt;ApplicationUser, ApplicationRole, string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim&gt;
      {
          public ApplicationUserStore(MyAppDb context)
              : base(context)
          {
          }
  
          public override async Task CreateAsync(ApplicationUser user)
          {
              await base.CreateAsync(user);
  
          }
      }
  
      
      public class ApplicationRoleStore : RoleStore&lt;ApplicationRole, string, ApplicationUserRole&gt;
      {
          public ApplicationRoleStore(MyAppDb context)
              : base(context)
          {
          }
      }
  
      public class ApplicationRoleManager : RoleManager&lt;ApplicationRole&gt;
      {
          public ApplicationRoleManager(IRoleStore&lt;ApplicationRole, string&gt; store)
              : base(store)
          {
          }
  
      }
  }
  </code></pre>
  <p><strong>UPDATE:</strong> I can get the error to go away on the creation of the <code>UserManager</code> by changing this:</p>
  <pre><code>public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
  {
      public ApplicationUserManager(IUserStore&lt;ApplicationUser&gt; store)
          : base(store)
      {
          this.PasswordValidator = (IIdentityValidator&lt;string&gt;)new MinimumLengthValidator(8);
          this.UserValidator = new UserValidator&lt;ApplicationUser&gt;(this) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true };
      }
  }
  </code></pre>
  <p>to this:</p>
  <pre><code>public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
  {
      public ApplicationUserManager(IUserStore&lt;ApplicationUser, string&gt; store)
          : base(store)
      {
          this.PasswordValidator = (IIdentityValidator&lt;string&gt;)new MinimumLengthValidator(8);
          this.UserValidator = new UserValidator&lt;ApplicationUser&gt;(this) { AllowOnlyAlphanumericUserNames = false, RequireUniqueEmail = true };
      }
  }
  </code></pre>
  <p>notice I just added <code>, string</code>, but it then puts the error &quot;The best overloaded method match for &quot;Microsoft.AspNet.Identity.UserMaager&lt;MyApp.Models.ApplicaitonUser&gt;.UserManager(Microsoft.AspNet.Identity.IUserStore&lt;MyApp.Models.ApplicationUser&gt;)' has some invalid arguments&quot; on <code>base(store)</code>.</p>
  <p>UPDATE 2: I changed this:</p>
  <pre><code>public class ApplicationUserManager : UserManager&lt;ApplicationUser&gt;
      {
          public ApplicationUserManager(IUserStore&lt;ApplicationUser, string&gt; store)
          ...
      }
  </code></pre>
  <p>to this:</p>
  <pre><code>public class ApplicationUserManager : UserManager&lt;ApplicationUser, string&gt;
      {
          public ApplicationUserManager(IUserStore&lt;ApplicationUser, string&gt; store)
          ...
      }
  </code></pre>
  <p>Notice the <code>' string</code> in <code>public class ApplicationUserManager : UserManager&lt;ApplicationUser, string&gt;</code>.  But now, guess what?  You guessed it--back to this issue: <a href="https://stackoverflow.com/questions/22698744/usermanager-createuser-password-thowing-entityvalidationerror-saying-id-is-re">UserManager.Create(user, password) thowing EntityValidationError saying Id is required?</a></p>
  <p><em><strong>What am I missing?</strong></em></p>