weird data association error RRS feed

  • Question

  • Hello, I'm experiencing a weird data association error:

    1. I associate some n:n data through a class method called by my PostCaseCreate plugin.
    2. I call a test method immediately after the method in step 1, to validate that the data exists as expected
    3. I call the same test method further downstream, but the data no longer exists as expected. Specifically, trying to access the data returns the following cast error:  "Unable to cast object of type 'Microsoft.Xrm.Sdk.Entity' to type 'MyProject.Entities.Contact'"

    The weird part is that this is *shared* code that works without error for another incident, created via a different scenario. Here's the code that I'm using to access the data:

        using (var xrm = new XrmContext(orgService))
            xrm.MergeOption = Microsoft.Xrm.Sdk.Client.MergeOption.NoTracking;
            xrm.LoadProperty(incident, "new_MyContacts");
            var myContacts = incident.new_MyContacts;

    Now that I've established that the code above works at 1 point, but then breaks at a later point, I can probably spend some time to determine, at what point the code breaks.  However, this seems like a weird error, especially since this is shared code working for another scenario, so I was wondering if anyone had any ideas about what might be causing this issue, or how to fix?
    Saturday, November 23, 2013 2:17 AM