_signInManager.PasswordSignInAsync() is throwing a NullReferenceException: Object reference not set to an instance of an object.
See original GitHub issueNullReferenceException: Object reference not set to an instance of an object.
lambda_method46(Closure , QueryContext )
Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync<TResult>(Expression query, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync<TSource, TResult>(MethodInfo operatorMethodInfo, IQueryable<TSource> source, Expression expression, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync<TSource, TResult>(MethodInfo operatorMethodInfo, IQueryable<TSource> source, LambdaExpression expression, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken)
Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore<TUser, TRole, TContext, TKey, TUserClaim, TUserRole, TUserLogin, TUserToken, TRoleClaim>.FindByNameAsync(string normalizedUserName, CancellationToken cancellationToken)
Microsoft.AspNetCore.Identity.UserManager<TUser>.FindByNameAsync(string userName)
Microsoft.AspNetCore.Identity.SignInManager<TUser>.PasswordSignInAsync(string userName, string password, bool isPersistent, bool lockoutOnFailure)
TherapyPlanner.OAuth.Pages.Login.Index.OnPost() in Index.cshtml.cs
+
var result = await _signInManager.PasswordSignInAsync(Input.Username, Input.Password, Input.RememberLogin, lockoutOnFailure: true);
We have 2 projects in the same solution
- IdentityContext : MultiTenantIdentityDbContext<User, Role, Guid, IdentityUserClaim<Guid>, UserRole, IdentityUserLogin<Guid>, IdentityRoleClaim<Guid>, IdentityUserToken<Guid>>
- ExampleDbContext : DbContext
We’re using the IdentityContext with Duende Server as an Identity Server with Code Grant with PKCE, and ExampleDbContext for our BusinessAPI, both as a multi tenant
I’ve added the migrations and updated the Identity Database, we can see the TenantId for the User,Role, etc…, when I click login after entering the username and password on the login page; the _signInManager.PasswordSignInAsync(Input.Username, Input.Password, Input.RememberLogin, lockoutOnFailure: true); is throwing a null exception
.NET 6, Duende Server V6
Issue Analytics
- State:
- Created 7 months ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
c# - SignInManager.PasswordSignInAsync Throwing Null ...
Any null objects in there will throw NULL REFERENCE EXCEPTION. To show some sample code (please see comments): public class ApplicationUser : ...
Read more >1.90 SignInManager not work · Issue #1752
but run project error NullReferenceException: Object reference not set to an instance of an object. WGO.UAM.Web.Pages.Accounts.LoginModel.
Read more >Object reference not set to an instance of an object
Following is the reason I could figure out just by reading the code. The code you gave will throw this error because the...
Read more >How can I fix the error: System.NullReferenceException
How can I fix the error: System.NullReferenceException: 'Object reference not set to an instance of an object.'.
Read more >SignInManager.PasswordSignInAsync Throwing Null Object ...
[NullReferenceException: Object reference not set to an instance of an object.] Microsoft.AspNet.Identity.<CreateAsync>d__0.MoveNext() +2112 System.Runtime.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I figured it out, I was using the tenantId in the UserClaim instead of the tenant name, the ClaimStrategy is now picking up the tenant in the HttpContext
Thank you
I’m glad you got it and sorry I couldn’t be more helpful. I think you’ve got on a good point-- the I’d could also be a valid thing to check. I also think there are situations where a single tenant might have multiple identifiers.