question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

_signInManager.PasswordSignInAsync() is throwing a NullReferenceException: Object reference not set to an instance of an object.

See original GitHub issue
NullReferenceException: 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

  1. IdentityContext : MultiTenantIdentityDbContext<User, Role, Guid, IdentityUserClaim<Guid>, UserRole, IdentityUserLogin<Guid>, IdentityRoleClaim<Guid>, IdentityUserToken<Guid>>
  2. 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:closed
  • Created 7 months ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hamedimbashercommented, Feb 21, 2023

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

0reactions
AndrewTriesToCodecommented, Feb 21, 2023

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found