skip to Main Content

I extended the IdentityUser in my app:

 public class ApplicationUser : IdentityUser
    {
        [Required]
        public string? Name { get; set; }
        public string? StreetAddress { get; set; }
        public string? City { get; set; }
        public string? State { get; set; }
        public string? PostalCode { get; set; }

        public int? CompanyId { get; set; }

        [ForeignKey("CompanyId")]
        public Company? Company { get; set; }

        [NotMapped]
        public string Role { get; set; }
    }

Updated all references replacing IdentityUser to Application and updated the pipeline.

The site runs but logging in gives me this error:

Microsoft.Data.SqlClient.SqlBuffer.ThrowIfNull()
Microsoft.Data.SqlClient.SqlBuffer.get_String()
Microsoft.Data.SqlClient.SqlDataReader.GetString(int i)
lambda_method93(Closure , QueryContext , DbDataReader , ResultContext , SingleQueryResultCoordinator )
Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable<T>+AsyncEnumerator.MoveNextAsync()
System.Threading.Tasks.ValueTask<TResult>.get_Result()
System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable<TResult>+ConfiguredValueTaskAwaiter.GetResult()
Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync<TSource>(IAsyncEnumerable<TSource> asyncEnumerable, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.ShapedQueryCompilingExpressionVisitor.SingleOrDefaultAsync<TSource>(IAsyncEnumerable<TSource> asyncEnumerable, CancellationToken cancellationToken)
Microsoft.AspNetCore.Identity.UserManager<TUser>.FindByNameAsync(string userName)
Microsoft.AspNetCore.Identity.SignInManager<TUser>.PasswordSignInAsync(string userName, string password, bool isPersistent, bool lockoutOnFailure)
WebRazor.Areas.Identity.Pages.Account.LoginModel.OnPostAsync(string returnUrl) in Login.cshtml.cs
ERROR -> +   115 var result = await _signInManager.PasswordSignInAsync(Input.Email, Input.Password, Input.RememberMe, lockoutOnFailure: true);

All the parameters in await _signInManager.PasswordSignInAsync have appropriate values. It throws at the result as it is null.

Here is the SQL Db

enter image description here

I have previous migrations and data in the db so I dont want to drop and rebuild unless I really need to.

Anyone have any wisdom here to fix this quickly.

enter image description here

When I apply the migration adding nullable to the Name I get this message:

enter image description here

2

Answers


  1. Double check that the username is the same as the email your passing in. If it’s not, that will cause that error as SignInManager.PasswordSignIn works off the username.

    Login or Signup to reply.
  2. Double-check the connection string is pointing to the same database. I’d also recommend using SQL Profiler to double-check the query being run against the database

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search