Trick for solving WCF RIA Services issue..

I am having the following issue: Sometimes, when I am issuing a DomainService call using WCF RIA Services, I got the callback right but the loadoperation I have assigned has no results, meaning no entities are returned and the “IsComplete” property is false. 

The following code resumes what I am doing, including the LoadOperation definition, the calling function and the callback function: 

LoadOperation lo; 

private void CallDomainService(){ 

DomainContext dc =  new DomainContext(); 

lo = dc.Load(dc.GetDataQuery()); 

lo.Completed += new EventHandler(lo_Completed); 


And it executes well and calls properly lo_completed… 

void lo_Completed(object sender, EventArgs e){ 

     if ((lo != null) && (lo.IsComplete == true)){

      if ((lo.Entities !=null) && (lo.Entities.Count() >= 1))         //Get the returned entity or whatever..



The issue is that I am getting properly the details of the load Operation, but some random times, it does not return the object properly, it is not null but its .IsComplete property is False and the Entities collection is empty, though that it has had been processed properly by the server.

The trick or workaround here is to get, in this exact case, the loadoperation from the server, which is a reference to the right load operation. The code should be like this:

LoadOperation<EntityType> lo2 = (LoadOperation<EntityType>)sender;

if ((lo2.IsComplete) && (lo2.Entities.Count() >= 1)) {

   EntityType Entity = lo2.Entities.First();



And with this, problem solved.

Are you having this random issue or others? anybody found why this is happening?

3 thoughts on “Trick for solving WCF RIA Services issue..

  1. Storing the LoadOperation as a class member to be used between different methods calls is not good idea because is leads to concurrency issues. Such LoadOperation barely can be called “client-side operation” – it’s just wrong concept.
    On other hand, Load() method of DomainContext has an overloaded version that receives the callback address that be called upon load completion. This callback receives the right LoadOperation as argument without any “trick” or “workaround”.


    1. Hi Oleg, Thanks for the information!! 🙂
      It is curious that most of the examples I’ve seen are written like this… when I have to use a LoadOperation I always make sure There is no other one running, with a flag/semaphore system so they don’t collide… but you’re right, it’s not as solid as what you are proposing :).
      And I agree that this is not only a Client’s work but a Load from the server, so it’s a more complex thing… maybe I haven’t explained properly..
      If you could put a simple example, it would be great.



  2. Here’s a simple example using one of the overload methods of the DomainContext.Load Method :

    private void Query_Loaded(LoadOperation lo) {
    context.Load(context.GetEntityQuery(), Query_Loaded, null);


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s