Error logging in using Facebook

2

Attempting to log in via facebook I come across with the following error:

  

Server Error in Application '/'.   Object reference not set to an instance of an object.   Description: An unhandled exception occurred during the execution of the   current Web request. Examine the stack trace for   more information about the error and where it originated in the code.   Exception Details: System.NullReferenceException:   object not set to an instance of an object.   Line 329: Line 330: // Sign in the user with this   Log in with your user ID and password.   var result = await SignInManager.ExternalSignInAsync (loginInfo,   isPersistent: false); Line 332: switch (result) Line 333:   {

     

[NullReferenceException: Object reference not set to 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.

asked by anonymous 23.01.2017 / 21:05

1 answer

1

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

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

Basically, this is: any and all requests will create an instance of ApplicationDbContext and ApplicationUserManager and will make them available for use.

The error happens because you're 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

   // ...
}
    
23.01.2017 / 23:58