title: UserManager.CreateAsync(user, password) stuck in infinite loop
body: <p>I'm trying to make a very simple implementation of an <code>IUserStore</code> that would essentially:</p>
  
  <ul>
  <li>use NHibernate</li>
  <li>save users in a single table (no claims/logins)</li>
  <li>store role names in the same table, in an nvarchar column (pipe (<code>'|'</code>) 
  separated if multiple items).</li>
  </ul>
  
  <p>When I run the following method:</p>
  
  <pre><code>[Fact]
  public void Create_A_User()
  {
      // _session is a valid NHibernate ISession object
      using (var userStore = new SimpleUserStore&lt;SimpleIdentityUser&gt;(_session))
      using (var userManager = new UserManager&lt;SimpleIdentityUser&gt;(userStore))
      {
          var user = new SimpleIdentityUser
          {
              UserName = "kenny_mccormick",
              RolesStr = "admin",
          };
  
          var createTask = userManager.CreateAsync(user, "the_password");
  
          var result = createTask.Result; // this never finishes...
      }
  }
  </code></pre>
  
  <p>the last line would never finish executing.</p>
  
  <p>The weird thing is that the <code>UserManager</code> never calls any of the functions in my <code>SimpleUserStore</code>; it gets stuck before that.</p>
  
  <p>Here are the components I defined:</p>
  
  <h3>The user class:</h3>
  
  <pre><code>public class SimpleIdentityUser : IUser
  {
      public virtual Guid UserId { get; set; }
      public virtual string PasswordHash { get; set; }
      public virtual string SecurityStamp { get; set; }
      public virtual string RolesStr { get; set; }
      public virtual string UserName { get; set; }
  
      public virtual string Id
      {
          get { return UserId.ToString(); }
      }
  }
  </code></pre>
  
  <h3>The User Store:</h3>
  
  <pre><code>public class SimpleUserStore&lt;TUser&gt; :
      IUserPasswordStore&lt;TUser&gt;,
      IUserRoleStore&lt;TUser&gt;,
      IUserSecurityStampStore&lt;TUser&gt;
      where TUser : SimpleIdentityUser
  {
      // ReSharper disable once StaticFieldInGenericType
      private static readonly Task EmptyTask = new Task(() =&gt; { });
  
      private readonly ISession _session;
  
      public SimpleUserStore(ISession session)
      {
          _session = session;
      }
  
      public Task&lt;TUser&gt; FindAsync(UserLoginInfo login)
      {
          return Task.FromResult((TUser) null);
      }
  
      public Task CreateAsync(TUser user)
      {
          _session.Save(user);
          return EmptyTask;
      }
  
      public Task UpdateAsync(TUser user)
      {
          // updates will (hopefully) be saved automatically when the current session is committed
          return EmptyTask;
      }
  
      public Task DeleteAsync(TUser user)
      {
          _session.Delete(user);
          return EmptyTask;
      }
  
      public Task&lt;TUser&gt; FindByIdAsync(string userId)
      {
          TUser user = null;
          Guid guidId;
  
          if (Guid.TryParse(userId, out guidId))
              user = _session.Get&lt;TUser&gt;(guidId);
  
          return Task.FromResult(user);
      }
  
      public Task&lt;TUser&gt; FindByNameAsync(string userName)
      {
          TUser user = _session.Query&lt;TUser&gt;().SingleOrDefault(u =&gt; u.UserName == userName);
          return Task.FromResult(user);
      }
  
      public Task SetPasswordHashAsync(TUser user, string passwordHash)
      {
          user.PasswordHash = passwordHash;
          return EmptyTask;
      }
  
      public Task&lt;string&gt; GetPasswordHashAsync(TUser user)
      {
          return Task.FromResult(user.PasswordHash);
      }
  
      public Task&lt;bool&gt; HasPasswordAsync(TUser user)
      {
          return Task.FromResult(user.PasswordHash != null);
      }
  
      public void Dispose()
      {
      }
  
      public Task AddToRoleAsync(TUser user, string role)
      {
          new SimpleRoleManager&lt;TUser&gt;(user).AddRole(role);
  
          return EmptyTask;
      }
  
      public Task RemoveFromRoleAsync(TUser user, string role)
      {
          new SimpleRoleManager&lt;TUser&gt;(user).DeleteRole(role);
  
          return EmptyTask;
      }
  
      public Task&lt;IList&lt;string&gt;&gt; GetRolesAsync(TUser user)
      {
          List&lt;string&gt; roles = new SimpleRoleManager&lt;TUser&gt;(user).GetRoles().ToList();
  
          return Task.FromResult((IList&lt;string&gt;) roles);
      }
  
      public Task&lt;bool&gt; IsInRoleAsync(TUser user, string role)
      {
          return Task.FromResult(new SimpleRoleManager&lt;TUser&gt;(user).IsInRole(role));
      }
  
      public Task SetSecurityStampAsync(TUser user, string stamp)
      {
          user.SecurityStamp = stamp;
          return EmptyTask;
      }
  
      public Task&lt;string&gt; GetSecurityStampAsync(TUser user)
      {
          return Task.FromResult(user.SecurityStamp);
      }
  }
  </code></pre>
  
  <h3>How I manage roles</h3>
  
  <p>Probably not so important, but here it is anyway:</p>
  
  <pre><code>public class SimpleRoleManager&lt;TUser&gt; where TUser : SimpleIdentityUser
  {
      private const string Separator = "|";
  
      private readonly TUser _user;
  
      public SimpleRoleManager(TUser user)
      {
          _user = user;
      }
  
      public string[] GetRoles()
      {
          return (_user.RolesStr ?? String.Empty)
              .Split(Separator.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
      }
  
      public bool IsInRole(string roleName)
      {
          return GetRoles().Contains(roleName);
      }
  
      public bool AddRole(string roleName)
      {
          var roles = GetRoles().ToList();
  
          if (roles.Contains(roleName))
              return false;
  
          roles.Add(roleName);
          SetRoles(roles);
          return true;
      }
  
      public bool DeleteRole(string roleName)
      {
          List&lt;string&gt; roles = GetRoles().ToList();
  
          if (!roles.Contains(roleName))
              return false;
  
          roles.Remove(roleName);
          SetRoles(roles);
          return true;
      }
  
      private void SetRoles(IEnumerable&lt;string&gt; roles)
      {
          _user.RolesStr = String.Join(Separator, roles);
      }
  }
  </code></pre>
  
  <p>I have been inspecting the <code>UserManager&lt;TUser&gt;</code> class with DotPeek, but found no obvious causes for this weird behavior.</p>
  
  <p>What could be causing this?</p>