{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Identity/issues/868","repository_url":"https://api.github.com/repos/aspnet/Identity","labels_url":"https://api.github.com/repos/aspnet/Identity/issues/868/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Identity/issues/868/comments","events_url":"https://api.github.com/repos/aspnet/Identity/issues/868/events","html_url":"https://github.com/aspnet/Identity/issues/868","id":159840881,"number":868,"title":"InvalidOperationException when calling UserManager.UpdateAsync()","user":{"login":"onedevteam","id":7267540,"avatar_url":"https://avatars.githubusercontent.com/u/7267540?v=3","gravatar_id":"","url":"https://api.github.com/users/onedevteam","html_url":"https://github.com/onedevteam","followers_url":"https://api.github.com/users/onedevteam/followers","following_url":"https://api.github.com/users/onedevteam/following{/other_user}","gists_url":"https://api.github.com/users/onedevteam/gists{/gist_id}","starred_url":"https://api.github.com/users/onedevteam/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/onedevteam/subscriptions","organizations_url":"https://api.github.com/users/onedevteam/orgs","repos_url":"https://api.github.com/users/onedevteam/repos","events_url":"https://api.github.com/users/onedevteam/events{/privacy}","received_events_url":"https://api.github.com/users/onedevteam/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-12T18:32:24Z","updated_at":"2016-06-12T20:02:02Z","closed_at":null,"body":"\r\nI have \r\n\r\n ```\r\n       public async Task<IActionResult> Edit(ApplicationUser model)\r\n        {\r\n\r\n            if (ModelState.IsValid)\r\n            {\r\n                var result = await _userManager.UpdateAsync(model);\r\n                if (result.Succeeded)\r\n                {\r\n                   // do something\r\n                }\r\n                RedirectToAction(\"Index\");\r\n            }\r\n            return View();\r\n        }\r\n\r\n```\r\n\r\nas my controller action. ModelState.IsValid is true. but when _userManager.UpdateAsync(model) executes, i get an error `InvalidOperationException: The instance of entity type 'edu_app_01.Models.ApplicationUser' cannot be tracked because another instance of this type with the same key is already being tracked. For new entities consider using an IIdentityGenerator to generate unique key values.`\r\n\r\nI'm using roles in mu app, and user is added to a role.\r\n\r\n _userManager object is injected in AccountController class constructor.\r\n\r\nHow can i resolve this?"},"comment":{"url":"https://api.github.com/repos/aspnet/Identity/issues/comments/225457167","html_url":"https://github.com/aspnet/Identity/issues/868#issuecomment-225457167","issue_url":"https://api.github.com/repos/aspnet/Identity/issues/868","id":225457167,"user":{"login":"brockallen","id":649492,"avatar_url":"https://avatars.githubusercontent.com/u/649492?v=3","gravatar_id":"","url":"https://api.github.com/users/brockallen","html_url":"https://github.com/brockallen","followers_url":"https://api.github.com/users/brockallen/followers","following_url":"https://api.github.com/users/brockallen/following{/other_user}","gists_url":"https://api.github.com/users/brockallen/gists{/gist_id}","starred_url":"https://api.github.com/users/brockallen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brockallen/subscriptions","organizations_url":"https://api.github.com/users/brockallen/orgs","repos_url":"https://api.github.com/users/brockallen/repos","events_url":"https://api.github.com/users/brockallen/events{/privacy}","received_events_url":"https://api.github.com/users/brockallen/received_events","type":"User","site_admin":false},"created_at":"2016-06-12T20:02:02Z","updated_at":"2016-06-12T20:02:02Z","body":"This is unrelated to your question, but beware using your `ApplicationUser` in MVC's model binding as you might be subject to an underposting or overposting attack. You should use formal view models and update models, and not your EF model directly. And then, yes, you will have to map between them. Taking this approach will also mean you will avoid the issue that you're raising here.\r\n\r\n@blowdart can provide some more official security guidance.\r\n"}}
{"actor":{"display_login":"brockallen"}}