title: SignInManager.PasswordSignInAsync Throwing Null Object Exception
body: <p><code>AccountController.cs</code> houses the <code>AccountController</code> class. The <code>Login</code> method of that class is failing. Specifically,</p>
  
  <pre class="lang-cs prettyprint-override"><code>var result = await SignInManager.PasswordSignInAsync(
      model.Email, model.Password, model.RememberMe, shouldLockout: true);
  </code></pre>
  
  <p>within the <code>Login</code> method is throwing <code>System.NullReferenceException</code>.</p>
  
  <p>I've verified that <code>model.Email</code>, <code>model.Password</code>, and <code>model.RememberMe</code> are not null. The next step is to dig in to <code>SignInManager</code>, which is an object on <code>AccountController</code> of type <code>ApplicationSignInManager</code>. The <code>get</code> accessor for <code>SignInManager</code>, which is called from the line above, was</p>
  
  <pre class="lang-cs prettyprint-override"><code>public ApplicationSignInManager SignInManager
  {
      get
      {
          return _signInManager ??
              HttpContext.GetOwinContext().Get&lt;ApplicationSignInManager&gt;();
      }
      // private set...
  }
  </code></pre>
  
  <p>which I rewrote as</p>
  
  <pre class="lang-cs prettyprint-override"><code>public ApplicationSignInManager SignInManager
  {
      get
      {
          var c = HttpContext.GetOwinContext();
          var m = c.Get&lt;ApplicationSignInManager&gt;();
          return _signInManager ?? m;
      }
      // private set...
  }
  </code></pre>
  
  <p>to debug and make sure that the <code>get</code> accessor was not returning <code>null</code>. It's not returning <code>null</code>. This tells me that something required inside <code>PasswordSignInAsync</code> is <code>null</code>.</p>
  
  <p>I've looked at <a href="https://www.symbolsource.org/MyGet/Metadata/aspnetwebstacknightly/Project/Microsoft.AspNet.Identity.Owin/2.2.0-alpha1-140725/Release/Default/Microsoft.AspNet.Identity.Owin/Microsoft.AspNet.Identity.Owin/SignInManager.cs?ImageName=Microsoft.AspNet.Identity.Owin" rel="noreferrer">the source</a> of <code>PasswordSignInAsync</code> and it does a pretty good job of guarding against null reference errors. I've also dug deeper into the methods called by <code>PasswordSignInAsync</code>. I simply don't see what could be throwing a null reference error.</p>
  
  <p>The stack trace from the error is pretty cryptic, and I don't see anything in it that helps. But for the sake of completeness, here it is:</p>
  
  <pre class="lang-cs prettyprint-override"><code>[NullReferenceException: Object reference not set to an instance of an object.]
  Microsoft.AspNet.Identity.&lt;CreateAsync&gt;d__0.MoveNext() +2112
  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
  System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
  Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +123
  Microsoft.AspNet.Identity.Owin.&lt;SignInAsync&gt;d__2.MoveNext() +408
  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
  System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
  Microsoft.AspNet.Identity.CultureAwaiter.GetResult() +63
  Microsoft.AspNet.Identity.Owin.&lt;SignInOrTwoFactor&gt;d__23.MoveNext() +2055
  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
  System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
  Microsoft.AspNet.Identity.CultureAwaiter`1.GetResult() +68
  Microsoft.AspNet.Identity.Owin.&lt;PasswordSignInAsync&gt;d__29.MoveNext() +1828
  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
  System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
  ApexRemingtonExternal.Controllers.&lt;Login&gt;d__2.MoveNext() in c:\Users\me\sc\project\Controllers\AccountController.cs:91
  System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
  System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
  System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
  System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task) +61
  System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +114
  System.Web.Mvc.Async.&lt;&gt;c__DisplayClass37.&lt;BeginInvokeAsynchronousActionMethod&gt;b__36(IAsyncResult asyncResult) +66
  System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
  System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +49
  System.Web.Mvc.Async.AsyncInvocationWithFilters.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3d() +117
  System.Web.Mvc.Async.&lt;&gt;c__DisplayClass46.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3f() +323
  System.Web.Mvc.Async.&lt;&gt;c__DisplayClass33.&lt;BeginInvokeActionMethodWithFilters&gt;b__32(IAsyncResult asyncResult) +44
  System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +47
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +136
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +102
  System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +50
  System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +72
  System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +185
  System.Web.Mvc.Async.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult) +42
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +133
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +56
  System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +40
  System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +34
  System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
  System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +44
  System.Web.Mvc.Controller.&lt;BeginExecute&gt;b__15(IAsyncResult asyncResult, Controller controller) +39
  System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +62
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
  System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +39
  System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +39
  System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +39
  System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +70
  System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +139
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +59
  System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
  System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +40
  System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
  System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9651688
  System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +155
  </code></pre>
  
  <p>I'd appreciate any help or guidance on what could be causing this <code>NullReferenceException</code>. Please let me know if I can add more detail (or remove some (lol!)). This is my and my company's first MVC project, so I'm sure I've broken something.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I should add that I stripped out Entity Framework from the project in favor of LINQ to SQL, which is what we rely on in all of our other projects. That means that I've had to implement my own versions of IUserStore, IRoleStore, etc.</p>