c# - Await is disposing DbContext - The ObjectContext instance has been disposed -
i have following in async
method has instance of dbcontext
passed it:
var userids = await getuserids(db);
with getuserids:
private async task<list<int>> getuserids(appcontext db) { var items = await db.items.where(s => s.isvalid).distinct().tolistasync(); // simplified return items; }
but get:
{"the objectcontext instance has been disposed , can no longer used operations require connection."}
i can force run removing await
, tolistasync
, that's bandaid. why context getting disposed?
i suspect caller of getuserids
method disposing context before operation completes. sure you're awaiting returned task before disposing context?
Comments
Post a Comment