How to resolve object disposed exception ASP.NET Core with Entity Framework and Identity

非 Y 不嫁゛ 提交于 2019-12-05 07:42:25

Declare your controller action as async Task, not async void.

With the latter, as soon as your method hits the first await, it returns control to the caller, and because ASP.NET now has no way to track its progress (as it would have when it returns a Task instead), it disposes your controller instance, and (most-likely) along with it any locally-scoped fields.


While you're there, as you're in an async method anyway, you should prefer the async version of the EF call; i.e. await _db.MapItems.SingleOrDefaultAsync()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!