NullReferenceException with Owin

此生再无相见时 提交于 2019-12-06 03:06:53

问题


I've just cloned a project to a new machine and I'm getting a hard-to-debug NullReferenceException on a MVC site with OWIN:

[NullReferenceException: Object reference not set to an instance of an object.]
   Microsoft.Owin.Security.Cookies.<AuthenticateCoreAsync>d__0.MoveNext() +664
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() +24
   Microsoft.Owin.Security.Infrastructure.<BaseInitializeAsync>d__2.MoveNext() +860
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +93
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +52
   System.Runtime.CompilerServices.TaskAwaiter.GetResult() +21
   Microsoft.Owin.Security.Infrastructure.<Invoke>d__0.MoveNext() +427
   System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() +22
   Microsoft.Owin.Host.SystemWeb.Infrastructure.ErrorState.Rethrow() +33
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +150
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +42
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +415
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

It occurs after

[assembly: OwinStartupAttribute(typeof(Website.Startup))]
namespace Website
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
        }
    }
}

but that's as much as I can discern as F10ing after this throws the exception - it never reaches the constructor of the first controller.

Has anyone experienced this before and/or can point me in the direction of what could be the cause of the error?


回答1:


The solution above didn't help me however I finally found the answer after trying many things.

I develop multiple solutions concurrently and something must have been getting tangled in the localhost cookies (each solution runs on a different localhost port). After clearing my localhost cookies the issue was resolved.




回答2:


Updating OWIN from v2 to v3 seems to fix this issue.

It's worth noting that all OWIN related packages should be updated too.




回答3:


Updating from OWIN v3.0 to v3.1 fixed the problem for me.



来源:https://stackoverflow.com/questions/27815532/nullreferenceexception-with-owin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!