0

I'm trying to unit test using nunit framework and I am getting the exception below:

SignInManager = 'SignInManager' threw an exception of type 'System.NullReferenceException'

How can resolve this issue?

Below code throwing exception:

ApplicationUser User = await SignInManager.UserManager.FindByNameAsync (login.UserName);

if (User != null) {

}

shashi
  • 37
  • 7
  • Possible duplicate of [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – slfan Aug 20 '19 at 04:57
  • already I tried above link but it does't work for me – shashi Aug 20 '19 at 06:12
  • As the error says: the property SignInManager.UserManager is null. You have to properly initialize it. See here https://stackoverflow.com/questions/27186310/applicationsigninmanager-class-is-null-during-authentication-process – slfan Aug 20 '19 at 06:20
  • This exception it is coming in when I am working unit testing in normal case it is working fine – shashi Aug 20 '19 at 06:35
  • Make sure you initialize ASP.NET Identity properly when unit testing or try to mock the call and return a valid user – slfan Aug 20 '19 at 07:59

0 Answers0