Async rule called during DataPortal_Fetch

Async rule called during DataPortal_Fetch

Old forum URL: posted on Thursday, February 21, 2013


I am using CSLA 4.2.2 with Silverlight (love it).

I have a question about the use of async rules.

I have some BusinessBase objects I fetch from the database.There is the possibility the database data can be incorrect, so I want to call BusinessRules.CheckRules() from within DataPortal_Fetch.

In this way the CSLA PropertyStatus controls in the GUI will flag any errors even if the user has not changed anything.

However I got caught out when doing this with async rules.

It looks like if you call an async rule from within DataPortal_Fetch or Child_Fetch on BusinessBase, and there is not time for the rule to complete before the object is serialised, the IsBusy flag for the BusinessBase object is locked on.

This causes weird GUI behaviour e.g. if you change the object you can never cancel the changes.

Has anyone else seen this problem? I'm not sure if this is a CSLA bug or I am doing something wrong?

I have worked around it by adding the following code to all of my async rules -

if (ApplicationContext.ExecutionLocation != ApplicationContext.ExecutionLocations.Silverlight)


_log.Debug("skipping async rule check as we are not executing on Silverlight");




Of course this means all of my async rules are ignored on the server side.

Kind Regards,


JonnyBee replied on Thursday, February 21, 2013

You have 2 options (from my braindump)


  1. Make rule async on SL and sync on .NET Serverside.
    ie - CSLA have separate registration of rules on server and client and can set IsAsync to a configured value on the serverside and code the the execute method to handle both sync/async behavior. 
  2. Add code to your rule so that it will not run for a given condition (as you have). 


Option1 makes your rule run in both client and server. 

Starting from CSLA 4.3  (IIRC) rules can specify:



I often find that especially async lookup rules should only run on the "rich" client side when a user changes the value, hence it is nice to be able to instruct the rule engine to not run the rule for a given set of conditions. This also means that the affected properties/input properties for excluded rules is ignored. replied on Thursday, February 21, 2013

Thanks Jonny that clears it up.

Perhaps it would be a good to have the CSLA framework throw a SerializationException on any BusinessBase object that still had rules running at the time it was attempted to be serialized. That would make this situation very obvious. It took a little time to work out what was happening here and it definitely broke my app.

RockfordLhotka replied on Monday, February 25, 2013

Starting in 4.5.13 the data portal will throw an exception if IsBusy is true when the object tries to return to the client.

Copyright (c) Marimer LLC