locked
Silverlight client throws exception during certain $expand scenarios RRS feed

  • Question

  • First let me say that I am using the interim release of the System.Data.Services.Client assembly in a Silverlight 2 application.

     

    I wanted to point out a possible defect that was introduced with the interim client. If the same entity is returned via 2 different $expand paths in a query, the client library throws an ArgumentException ("An item with the same key has already been added.") Here's a sample of a query that causes this exception:

     

    http://localhost:2650/MyService.svc/PROJECT(guid'31e61b96-07d2-4c37-b552-5fca024a63ae')?$expand=PROJECT_OWNERSHIP/USER,PROJECT_TASK/USER

     

    In this example a Project is associated with one or more Users and a ProjectTask is associated with a single User. If the same user is associated with the Project and the ProjectTask, then the exception occurs.  In my case, the exception occurs during a call to ToList or First on the result of a call to EndExecute.

     

    For what it's worth, here is some additional information:

    • When I examine the Fiddler trace for this scenario, I can see that the data service successfully returns the query results. So it seems that the error occurs during the process of transforming those results into objects.
    • This problem did not occur in the Silverlight 2 Beta 2 client library. It was introduced with the interim release.

    Will this be fixed in the final RTM of the client?

     

    Thanks

    Rob

    Monday, September 15, 2008 6:01 PM

Answers

  • Rob, thanks a lot for following up on this. I really appreciate it. As monica said, we have the bug reproing at our end and we will be fixing this for our coming version.

     

    I hope you can use the work-around for now.

    Thanks once agian for helping us find this issue.

     

    Thanks

    Pratik

     

    Friday, October 10, 2008 6:48 PM
    Moderator

All replies

  • Can you please send me the schema for this - just the xml returned by the $metadata endpoint will be good enough?

     

    Thanks

    Pratik

     

    Tuesday, September 16, 2008 6:53 PM
    Moderator
  • Pratik,

     

    I sent you the $metadata XML via email.

     

    Thanks

    Rob

     

    Tuesday, September 16, 2008 7:21 PM
  • I tried the same scenario with the current silverlight  bits and was not able to repro this. So this will be fixed in the RTM bits. Thanks a lot for reporting this to us.

     

    Thanks

    Pratik

     

    Wednesday, September 17, 2008 4:54 PM
    Moderator
  • Hi Pratik,

     

    Your post was unclear as to whether you could reproduce the issue with the interim release. Did you verify that it is a real issue in the interim release or just that it is not an issue in the RTM?

     

    Rob

     

    Wednesday, September 17, 2008 5:01 PM
  • As of now, i have tried this with the latest bits and made sure i didn't see this issue. Someone from my team is going to give it a shot with the interim bits sometime tomorrow and see if reproes. If it does not repro with the interim bits, i will ping you again for more information.

     

    Thanks

    Pratik

    Thursday, September 18, 2008 12:28 AM
    Moderator
  • Hello,

     

    I tried a sample repro with the Astoria interim bits and I don't see any problem.

    Could you please send me more information, the data you are seeing in Fiddler and the snippet of code you are using so I can try it out?

    Besides the query you are executing, are you tracking other entities in the context?

     

    Thanks,

    Monica Frintu

    Friday, September 19, 2008 12:11 AM
    Moderator
  • Hi Monica,

     

    I attempted to send you (and Pratik) the information you requested via email but the email address you advertise in this forum rejected my email. The Fiddler response is too long to post here so if you cannot get that data from Pratik, I need a way to send the information to you.

     

    Aside from the Fiddler traces, here are the answers to your other questions:

     

    Here's the code snippet that is sending the query:

    var qry = from p in TheContext.ASE_PROJECT

    where p.ASE_PROJECT_ID == projectID

    select p;

    DataServiceQuery<ASE_PROJECT> projectQuery = (DataServiceQuery<ASE_PROJECT>)qry;

    projectQuery = projectQuery.AddQueryOption("$expand", "ASE_PROJECT_OWNERSHIP/ASE_USER,ASE_PROJECT_TASK/ASE_USER1,ASE_PROJECT_STATUS");

    projectQuery.BeginExecute(callback, projectQuery);

     

    Here's the callback code that is handling  the response:

    DataServiceQuery<ASE_PROJECT> projectQuery = (DataServiceQuery<ASE_PROJECT>)result.AsyncState;

    IEnumerable<ASE_PROJECT> projects = projectQuery.EndExecute(result);

    AseProject = projects.First();

     

    The exception is thrown in the call to projects.First(). I changed projects.First() to projects.ToList() and the same exception was thrown.

     

    As to your last question, I am using a new context and this is the only query/response that is run in that context prior to the exception.

     

    Thanks

    Rob

     

     

     

    Friday, September 19, 2008 2:18 PM
  • I reproduced the issue in a smaller application using the RC0 bits. 

     

    The key to the problem is the MergeOption setting on my DataServiceContext. When I have it set to MergeOption.OverwriteChanges, the exception occurs. Could you please let me know if you can reproduce the issue given this new information? Am I wrong in using this MergeOption? Is there a way to work around the problem and still have the same merge behavior?

     

    Thanks

    Rob

    Tuesday, October 7, 2008 3:15 PM
  • I marked this post as unanswered because the problem still exists in the RC0 bits.

     

    Thanks

    Rob

     

    Wednesday, October 8, 2008 12:56 PM
  • Hi Rob,

     

    I was able to repro the exception by changing the option of MergeOption property. Since you are saying you create a fresh new DataServiceContext object, there shouldn't be any difference in using AppendOnly or OverwriteChanges.

    So, you can use AppendOnly and this should fix the problem for now.

    I will get back to you as soon as we have more info on the problem.

     

    Thanks,

    Monica

    Wednesday, October 8, 2008 5:06 PM
    Moderator
  • Rob, thanks a lot for following up on this. I really appreciate it. As monica said, we have the bug reproing at our end and we will be fixing this for our coming version.

     

    I hope you can use the work-around for now.

    Thanks once agian for helping us find this issue.

     

    Thanks

    Pratik

     

    Friday, October 10, 2008 6:48 PM
    Moderator