I canÂ´t figure it out, but I have two MVC projects with Single Sign On log in that I needed to reseed, and after the seed, userStore variable returns with a null value.
This is my code(note that the db works fine and finds all my tables and also the AspNetUsers table):
private ApplicationDbContext db = new ApplicationDbContext();
and in the Index method(userManager row throws the exception since userStore has null value):
var userStore = new UserStore<ApplicationUser>(db); var userManager = new UserManager<ApplicationUser>(userStore); var userId = User.Identity.GetUserId(); var user = userManager.FindById(userId);
I havenÂ´t changed a single row of code between a working solution and the latest seed, but I added the SSO configuration between the last two seeds.
Tried to restart computer and the problem persists, but when I try logging in with another user, it works fine. When trying to login with the first user again i get another error:
The provided anti-forgery token was meant for a different claims-based user than the current user.
So I tried in a "InPrivate Window" and I get the original problem with the first user but any other user gets the anti-forgery error instead.
Tried running the project again and the original error occurs fÃ¶r the first user but the next I try logging in with throws the anti-forgery error.
After that trying to log in with another user, the first user also throws the anti-forgery error.
This specific behaviour seems to be connected to IE. In chrome and Firefox I get the original error, but I cant replicate any of the anti-forgery errors in any combination of order of logins or users, but the first user keeps getting original exception thrown.
So I guess it is the original error that is the problem for any browser.
Since I know the exact line of code that causes the problem, I think I can safely assume the following is related in some way.. I can set breakpoints on the following:
var userStore = new UserStore<ApplicationUser>(db); var userManager = new UserManager<ApplicationUser>(userStore);
but can no longer set a breakpoint on this line:
var userId = User.Identity.GetUserId();
Finally found the solution for me in another thread. I disabled this option:
Project Properties> Build> Optimize code
It fixed both the original problem and also the problem in the very end with breakpoints