Error while logging in using Facebook

Asked

Viewed 108 times

2

Trying to login through facebook I come across the following error:

Server Error in Application '/'. Undefined object reference for an object instance. Description: An untreated exception occurred during the execution of current web request. Examine stack tracking to get more information about the error and where it originated in the code. Exception Details: System.Nullreferenceexception: Reference of object not defined for an object instance. Line 329: Line 330: // Sign in the user with this External login Provider if the user already has a login Line 331:
var result = await Signinmanager.Externalsigninasync(loginInfo, isPersistent: false); Line 332: switch (result) Line 333: {

[Nullreferenceexception: Object reference not defined for a instance of an object.]
Euvotoaf.Controllers.d__26.Movenext() in C: Users Renan Documents visual studio 2015 Projects Euvotoaf Euvotoaf Controllers Accountcontroller.Cs:331
System.Runtime.Compilerservices.TaskAwaiter.Throwfornonsuccess(Task task) +92
System.Runtime.Compilerservices.TaskAwaiter.Handlenonsuccessanddebuggernotification(Task task) +58
System.Web.Mvc.Async.Taskasyncactiondescriptor.Endexecute(Iasyncresult asyncResult) +97
System.Web.Mvc.Async.<>c__DisplayClass37.b__36(Iasyncresult asyncResult) +17
System.Web.Mvc.Async.Wrappedasyncresult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.Asynccontrolleractioninvoker.Endinvokeactionmethod(Iasyncresult asyncResult) +32
System.Web.Mvc.Async.Asyncinvocationwithfilters.b__3d() +50 System.Web.Mvc.Async.<>c__DisplayClass46.b__3f() +225 System.Web.Mvc.Async.<>c__DisplayClass33.b__32(Iasyncresult asyncResult) +10
System.Web.Mvc.Async.Wrappedasyncresult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.Asynccontrolleractioninvoker.Endinvokeactionmethodwithfilters(Iasyncresult asyncResult) +34
System.Web.Mvc.Async.<>c__DisplayClass2b.b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21.b__1e(Iasyncresult asyncResult) +100
System.Web.Mvc.Async.Wrappedasyncresult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Async.Asynccontrolleractioninvoker.Endinvokeaction(Iasyncresult asyncResult) +27
System.Web.Mvc.Controller.b__1d(Iasyncresult asyncResult, Executecorestate innerState) +13
System.Web.Mvc.Async.Wrappedasyncvoid1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Controller.Endexecutecore(Iasyncresult asyncResult) +36 System.Web.Mvc.Controller.b__15(Iasyncresult asyncResult, Controller) +12
System.Web.Mvc.Async.Wrappedasyncvoid1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.Controller.Endexecute(Iasyncresult asyncResult) +26
System.Web.Mvc.Controller.System.Web.Mvc.Async.Iasynccontroller.Endexecute(Iasyncresult asyncResult) +10
System.Web.Mvc.MvcHandler.b__5(Iasyncresult asyncResult, Processrequeststate innerState) +21
System.Web.Mvc.Async.Wrappedasyncvoid1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase
1.End() +49
System.Web.Mvc.MvcHandler.Endprocessrequest(Iasyncresult asyncResult) +28 System.Web.Mvc.MvcHandler.System.Web.Ihttpasynchandler.Endprocessrequest(Iasyncresult result) +9
System.Web.Callhandlerexecutionstep.System.Web.HttpApplication.Iexecutionstep.Execute() +9765121 System.Web.Httpapplication.Executestep(Iexecutionstep step, Boolean& completedSynchronously) +155

Threshing the application, I noticed that the error is in the following line:

var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false);

And getting a little more into my class builder ApplicationSignInManager in the Return of the line:

 return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>();

Is set as Null. One detail that may be important, is that I am customizing the identity, to use the Guid as the primary key instead of the default String.

I put the classes IdentityConfig and Start.Auth in the gist for further detail.

How do I fix it ?

  • The main part of the error was missing: the stack trace

  • So HttpContext.GetOwinContext().Get<ApplicationSignInManager>() is returning null?

1 answer

1


See the method ConfigureAuth() in class Startup, in it has the following commented line app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);.

Realize that the error you are getting is that the line HttpContext.GetOwinContext().Get<ApplicationSignInManager>(); is returning null.

Basically, it’s as follows: any and all requests will create an instance of ApplicationDbContext and ApplicationUserManager and will make them available for use.

The mistake happens because you are trying to capture ApplicationSignInManager, but it was not created. So, uncomment the third and everything should work.

public void ConfigureAuth(IAppBuilder app)
{
    app.CreatePerOwinContext(ApplicationDbContext.Create);
    app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
    app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); //Esta linha estava comentada

   // ...
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.