3

Why am I getting exception when using PasswordSignInAsync on .NET Core Identity? Microsoft.AspNetCore.Identity

await _signInManager.PasswordSignInAsync(user.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: false);

An unhandled exception occurred while processing the request.
SqlException: Invalid column name 'NormalizedName'.
Invalid column name 'ConcurrencyStamp'.
Invalid column name 'NormalizedName'.
Microsoft.Data.SqlClient.SqlCommand+<>c.<ExecuteDbDataReaderAsync>b__164_0(Task<SqlDataReader> result)

I can create user, reset password and so on. 'NormalizedName' is not even part of Microsoft.AspNetCore.Identity. All the columns exist in my table

select LockoutEnd, TwoFactorEnabled, PhoneNumberConfirmed, PhoneNumber, ConcurrencyStamp, SecurityStamp, 
PasswordHash, EmailConfirmed, NormalizedEmail, Email, NormalizedUserName, UserName, Id, LockoutEnabled, AccessFailedCount
from [dbo].[AspNetUsers]
Manny
  • 31
  • 1
  • 2
  • Not sure how this is possible but I got it working by making these changes in the Startup.cs ` services.AddIdentity(options => { options.SignIn.RequireConfirmedAccount = true; }).AddEntityFrameworkStores(); ` to ` services.AddDefaultIdentity(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores();` – Manny Aug 17 '20 at 19:20

1 Answers1

5

The exception is actually coming from the AspNetRoles table and not the AspNetUsers one. If you've migrated an old Asp.Net Identity to Asp.Net Core, then there's two new fields you need to add to the Roles table. Here's a migration for that:

public partial class Identity : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.AddColumn<string>(
            name: "NormalizedName",
            table: "AspNetRoles",
            type: "nvarchar(256)",
            maxLength: 256,
            nullable: true);

        migrationBuilder.AddColumn<string>(
            name: "ConcurrencyStamp",
            table: "AspNetRoles",
            type: "nvarchar(max)",
            nullable: true);
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropColumn(
            name: "ConcurrencyStamp",
            table: "AspNetRoles");

        migrationBuilder.DropColumn(
            name: "NormalizedName",
            table: "AspNetRoles");
    }
}

If you want the full Identity migration including the users, claims and other tables, you can refer to my answer to this question: https://stackoverflow.com/a/65003440/1348324

Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100