I have this error "An asynchronous module or handler completed while an asynchronous operation was still pending" in my MVC 5 web application when deleting children from my model, via a grid which fires ajax requests to the MVC controller.
There is an async business rule on the parent, IsAsync = true and context.Complete is called when it Executes.
My delete signature in the MVC controller is (using a Kendo grid here);
public async Task<JsonResult> CustomerUser_Destroy([DataSourceRequest] DataSourceRequest request, AccountUserEdit record, int id)
and the content......
if (record != null)
{
//get existing model(s)
var parentModel = AccountEdit.GetAccount(record.AccountId);
AccountUserEdit child = (from p in parentModel.CustomerAccountUsers
where p.Id == id
select p).First();
//delete it
parentModel.CustomerAccountUsers.Remove(child);
//can we save it
if (parentModel.IsSavable)
{
parentModel = await parentModel.SaveAsync(true);
}
else
{
//get broken rules message.
throw new ValidationException(MyBrokenRulesMessage.GetBrokenRules(parentModel, child));
}
}
return Json(ModelState.ToDataSourceResult());
I have this wrapped within a try catch exception block but the error is not being caught here.
So the behavior to reproduce the error is that I can add some children in my MVC grid and they are saved ok. If I then start removing them I get the error. Oddly, if I refresh the browser page, and then delete a child it works.
Hard to track the error down.....so what am I doing wrong?
"An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
[InvalidOperationException: An asynchronous module or handler completed while an asynchronous operation was still pending.]
"
Any pointers appreciated.