My RoleController
:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult RoleAddToUser(string UserName, string RoleName)
{
ApplicationUser user = context.Users.Where(u => u.UserName.Equals(UserName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault();
var account = new AccountController();
account.UserManager.AddToRole(user.Id, RoleName);
ViewBag.ResultMessage = "Role created successfully !";
// prepopulat roles for the view dropdown
var list = context.Roles.OrderBy(r => r.Name).ToList().Select(rr => new SelectListItem { Value = rr.Name.ToString(), Text = rr.Name }).ToList();
ViewBag.Roles = list;
return View("ManageUserRoles");
}
My AccountController
:
[Authorize]
public class AccountController : Controller
{
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
public ApplicationUserManager UserManager
{
get
{
return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>();
}
}
}
On the last line above is where it breaks. I am just trying to add a user to a role.
Object reference not set to an instance of an object.
[NullReferenceException: Object reference not set to an instance of an object.]
System.Web.HttpContextBaseExtensions.GetOwinEnvironment(HttpContextBase context) +34
System.Web.HttpContextBaseExtensions.GetOwinContext(HttpContextBase context) +50
Edit: I think the problem is deeper than any mentioned in the "possible duplicate of another question". I don't think I even have the right references working, even though I see them in references in Solution Explorer, try to re-add them, and try to use NugGet to import/update them.
Not sure how or why this is happening but somehow I'm not referencing the OwinContext which be the might cause in the trace returning an Object reference not set to an instance.
I don't even know how to explain things this MVC/Owin/EF/references is slowly making me miss MS Access, Visual Basic and DLL Hell.