Vibrant discussion about CSLA .NET and using the framework to build great business applications.

Forum has moved

New location: CSLA .NET forum

CSLA .NET Resources:
  • CSLA .NET forum
  • CSLA .NET home page
  • An asynchronous module or handler completed while an asynchronous operation was still pending.

    rated by 0 users
    Not Answered This post has 0 verified answers | 2 Replies | 0 Followers

    Top 50 Contributor
    138 Posts
    richardb posted on Tue, May 26 2015 4:24 AM

    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

                        //can we save it
                       if (parentModel.IsSavable)
                           parentModel = await parentModel.SaveAsync(true);
                           //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.

    All Replies

    Top 10 Contributor
    4,106 Posts
    Andy replied on Wed, May 27 2015 8:52 AM

    Could the error be misleading?  Are you getting the newly inserted child objects DB IDs back to the client?  The fact that refreshing the page fixes it makes me think that the client data is out of sync and refreshing builds a new page with all the IDs in place.

    Top 50 Contributor
    138 Posts

    Thanks Andy.

    The error may well be misleading, the web app gives the error 500 internal error and using Fiddler this is the response I see.  

    Perhaps related to my other post here, what I did was;

    "In the end, the solution I used was to use a viewmodel.  So when the grid loads, I map (using the wondeful AutoMapper) my children into a list of viewmodels (simple poco's without a Parent property) and bind that to the grid.  The kendo grid can then post the child vm back nicely and then I load up my parent model and its children, find the model I'm editing and map the changes back from the vm into the child - thus I get the csla business rules firing as required.

    The viewmodel works for me in my MVC world.  If I was doing a WPF UI I know from experience that the grid controls do tend to support complex objects, and that a WPF grid would typically be able to do a save call on the parent which would then ripple down to the children and save our amended child."

    Ultimately I think the trick here is to remember that inline grid editing in an MVC world is often really a postback updating an individual record, thus you need a root BusinessBase object model to support this.

    Hopefully I explained that ok.  


    Page 1 of 1 (3 items) | RSS

    Copyright (c) 2006-2014 Marimer LLC. All rights reserved.
    Email admin@lhotka.net for support.
    Powered by Community Server (Non-Commercial Edition), by Telligent Systems