I've used ASP.Net Identity a couple of times now. On a new project I seem to be having an issue creating a user.
When calling _userManager.Create() I get the following error.
The string '{ Name: IX_UserId, Order: 0 }' was not
in the expected format to be deserialized by the
IndexAnnotationSerializer. Serialized values are expected to have
the format '{ Name: 'MyIndex', Order: 7, IsClustered: True,
sUnique: False } { } { Name: 'MyOtherIndex' }'.
I've tried using the following DbContext, which - apart from the class name - is identical to the DbContext i have in another project, that works
public partial class ISIdentityDbContext : IdentityDbContext<IdentityUser>
{
public ISIdentityDbContext()
: base("ISIdentityDbContext")
{ }
public DbSet<ApplicationUserUserInfoMap> ApplicationUserUserInfoMap { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
// asp.net identity - call the tables something else..
modelBuilder.Entity<IdentityRole>().ToTable("ApplicationRoles");
modelBuilder.Entity<IdentityUserClaim>().ToTable("ApplicationUserClaims");
modelBuilder.Entity<IdentityUserLogin>().ToTable("ApplicationUserLogins");
modelBuilder.Entity<IdentityUserRole>().ToTable("ApplicationUserRoles");
modelBuilder.Entity<IdentityUser>().ToTable("ApplicationUser");
}
}
I have tried the following:
using (ISIdentityDbContext context = new ISIdentityDbContext())
{
_userManager = new UserManager<IdentityUser>(new UserStore<IdentityUser>(context));
IdentityUser user = new IdentityUser();
user.UserName = "darren";
_userManager.Create(user, "password");
}
And also, the one I really need to get working as it's extending the ApplicationUser (IdentityUser)
using (ISIdentityDbContext context = new ISIdentityDbContext())
{
_userManager = new UserManager<LegacyApplicationUser>(new UserStore<LegacyApplicationUser>(context));
ApplicationUserUserInfoMap map = new ApplicationUserUserInfoMap();
map.UserGUID = "anIdFromAnotherTable";
LegacyApplicationUser user = new LegacyApplicationUser();
user.UserInfoMap = map;
user.UserName = "darren";
_userManager.Create(user, "password");
}
Where my LegacyApplicationUser is:
public class LegacyApplicationUser : IdentityUser
{
public virtual ApplicationUserUserInfoMap UserInfoMap { get; set; }
}
public class ApplicationUserUserInfoMap
{
public int ID { get; set; }
public string UserGUID { get; set; }
}
I'm totally stumped...no matter whether i rebuild my database to match the standard Identity users or use my extended version i keep getting the same exception shown at the top.
I've likely missed something, though can't figure what....
Any ideas?
IX_UserIdappears to be an index on UserId column.