C# SignInManager.PasswordSignInAsync引发空对象异常

C# SignInManager.PasswordSignInAsync引发空对象异常,c#,asp.net-mvc,asp.net-mvc-5,nullreferenceexception,owin,C#,Asp.net Mvc,Asp.net Mvc 5,Nullreferenceexception,Owin,AccountController.cs包含AccountController类。该类的Login方法失败。具体来说, var result=await-SignInManager.PasswordSignInAsync( model.Email、model.Password、model.RememberMe、shouldllockout:true); 在Login方法中,抛出System.NullReferenceException 我已经验证了model.Email、model.Passw

AccountController.cs
包含
AccountController
类。该类的
Login
方法失败。具体来说,

var result=await-SignInManager.PasswordSignInAsync(
model.Email、model.Password、model.RememberMe、shouldllockout:true);
Login
方法中,抛出
System.NullReferenceException

我已经验证了
model.Email
model.Password
model.RememberMe
不为空。下一步是深入到
SignInManager
,它是
AccountController
上类型为
ApplicationSignInManager
的对象。从上一行调用的
SignInManager
get
访问器无效

公共应用程序SignInManager SignInManager
{
得到
{
返回\u签名管理员??
HttpContext.GetOwinContext().Get of
PasswordSignInAsync
,它在防止空引用错误方面做得非常好。我还深入研究了
PasswordSignInAsync
调用的方法。我根本看不到有什么可能抛出空引用错误

错误的堆栈跟踪非常隐晦,我看不出有什么帮助。但为了完整起见,这里是:

[NullReferenceException:对象引用未设置为对象的实例。]
Microsoft.AspNet.Identity.d_u0.MoveNext()+2112
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter`1.GetResult()+24
Microsoft.AspNet.Identity.CultureaWater`1.GetResult()+123
Microsoft.AspNet.Identity.Owin.d__2.MoveNext()+408
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter.GetResult()+21
Microsoft.AspNet.Identity.CultureAwater.GetResult()+63
Microsoft.AspNet.Identity.Owin.d_u23.MoveNext()+2055
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter`1.GetResult()+24
Microsoft.AspNet.Identity.CultureaWater`1.GetResult()+68
Microsoft.AspNet.Identity.Owin.d_u29.MoveNext()+1828
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter`1.GetResult()+24
c:\Users\me\sc\project\Controllers\AccountController.cs:91中的ApexRemingtonExternal.Controllers.d\uu 2.MoveNext()
System.Runtime.CompilerServices.TaskWaiter.ThrowForNonSuccess(任务任务)+93
System.Runtime.CompilerServices.TaskWaiter.HandleNonSuccessAndDebuggerNotification(任务)+52
System.Runtime.CompilerServices.TaskWaiter.GetResult()+21
System.Threading.Tasks.TaskHelperExtensions.ThrowIfFaulted(任务)+61
System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)+114
System.Web.Mvc.Async.c__显示类37.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.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)+49
System.Web.Mvc.Async.AsyncInvocationWithFilters.b__3d()+117
System.Web.Mvc.Async.c__DisplayClass46.b__3f()+323
System.Web.Mvc.Async.c__显示类33.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.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+102
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)+50
System.Web.Mvc.Async.c__显示类2b.b__1c()+72
System.Web.Mvc.Async.c__显示类21.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.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+56
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)+40
System.Web.Mvc.Controller.b_u1d(IAsyncResult asyncResult,ExecuteCorerate innerState)+34
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+70
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End()+139
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+59
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+40
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)+44
System.Web.Mvc.Controller.b_uu15(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.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+59
System.Web.Mvc.Async.asyncResultRapper.End(IAsyncResult asyncResult,对象标记)+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.b_uu5(IAsyncResult asyncResult,ProcessRequestState innerState)+39
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)+70
System.Web.Mvc.Async.WrappedAs
public class ApplicationUser : IdentityUser
{
    ...//some additional properties goes here

    public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
    {
        // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
        var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);

        //my custom claims
        List<Claim> claims = new List<Claim>
        {
            new Claim("FirstName", FirstName.ToString()),
            new Claim("MiddleName", MiddleName.ToString()),
            new Claim("LastName", LastName.ToString()),
            new Claim("Position", Position.ToString()) //if Position is NULL, it will throw null reference exception
        };

        userIdentity.AddClaims(claims);

        return userIdentity;
    }
}