title: Business Process Error when Merging Case records via C#
body: <p>I created a post-operation plugin on create of "incident."  The rule is to merge any "incident" created with the same title within 30 days.  I have query expressions that get me the data that I need.  If there are 0 matches with the same title the case is created, if there are more than one match, I query that title by createdon ascending to get me the very first "incident" created ID. My tracers show that all the data is correct that I'm getting. My problem is at the merge with the following code below:</p>
  
  <pre><code>                                //merge tickets here
                              EntityReference masterTicket = new EntityReference();
                              masterTicket.Id = (Guid)masterTicketId;
                              masterTicket.LogicalName = "incident";
  
                              MergeRequest merge = new MergeRequest();
                              merge.SubordinateId = targetIncidentId;
                              merge.Target = masterTicket;
                              merge.PerformParentingChecks = false;
                              tracer.Trace($"Merging {targetIncidentId} into {masterTicket.Id}.");
                              var merged = (MergeResponse)service.Execute(merge);
                              tracer.Trace($"Merged Response: {merged}");
  </code></pre>
  
  <p>I have used the following examples here: <a href="https://docs.microsoft.com/en-us/dotnet/api/microsoft.crm.sdk.messages.mergerequest?view=dynamics-general-ce-9" rel="nofollow noreferrer">merge link</a></p>
  
  <p>The issue I think might be that all code that I have seen they are updating records as well.  I don't want to update any of the records, I just want to merge the records with the matching title.</p>
  
  <p>I've been fighting with this for awhile now and any help would be appreciated.</p>
  
  <p>Thanks</p>
  
  <p><strong>EDIT:</strong> The plugin trace log is show it's failing at:</p>
  
  <pre><code>var merged = (MergeResponse)service.Execute(merge);
  </code></pre>
  
  <p>Because the tracer after that line is not showing in the trace logs.</p>
  
  <blockquote>
    <p><strong>EDIT:</strong>  The following is the error log file:</p>
    
    <blockquote>
  <pre><code>Unhandled exception:  Exception type: System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]
  </code></pre>
      
      <p>Message: An error occurred in the following plugin:Detail: 
      <br>
      80609179-2920-4a9e-91b9-65b10a3a3a4c<br>
      -2147220891   
          
            OperationStatus
            0
          
          
            SubErrorCode
            -2146233088
                http%3a%2f%2fgo.microsoft.com%2ffwlink%2f%3fLinkID%3d398563%26lcid%3d1033%26error%3dMicrosoft.Crm.CrmException%26client%3dplatform%26sv%3d9.0.42.1001%26de%3dLive%26opsys%3dMicrosoft+Windows+NT+10.0.14393.0%26errorCode%3d-2147220891
      An error occurred in the following plugin:<br>
      2019-10-21T14:20:08.3608048Z<br>
      false            </p>
      
      <p>[ORG_Dynamics365: ORG_Dynamics365.TicketStacking]
      [e5b0700e-e3f0-e911-a812-000d3a33f7ca: ORG_Dynamics365.TicketStacking:
      Create of incident] Entered
      Microsoft.Dynamics.Service.Plugins.PreOperationIncidentCreate.Execute(),
      Correlation Id: 970488ac-6888-4eb6-9294-cdf1098e5371, Initiating User:
      bc80c76a-38d3-e911-a9b8-000d3a367d35 Exiting
      Microsoft.Dynamics.Service.Plugins.PreOperationIncidentCreate.Execute(),
      Correlation Id: 970488ac-6888-4eb6-9294-cdf1098e5371, Initiating User:
      bc80c76a-38d3-e911-a9b8-000d3a367d35 Entered
      Microsoft.Dynamics.Service.Plugins.PreOperationIncidentCreateEntitlement.Execute(),
      Correlation Id: 970488ac-6888-4eb6-9294-cdf1098e5371, Initiating User:
      bc80c76a-38d3-e911-a9b8-000d3a367d35 Exiting
      Microsoft.Dynamics.Service.Plugins.PreOperationIncidentCreateEntitlement.Execute(),
      Correlation Id: 970488ac-6888-4eb6-9294-cdf1098e5371, Initiating User:
      bc80c76a-38d3-e911-a9b8-000d3a367d35 Entered
      Microsoft.Dynamics.Service.Plugins.PostOperationIncidentCreateEntitlement.Execute(),
      Correlation Id: 970488ac-6888-4eb6-9294-cdf1098e5371, Initiating User:
      bc80c76a-38d3-e911-a9b8-000d3a367d35 Exiting
      Microsoft.Dynamics.Service.Plugins.PostOperationIncidentCreateEntitlement.Execute(),
      Correlation Id: 970488ac-6888-4eb6-9294-cdf1098e5371, Initiating User:
      bc80c76a-38d3-e911-a9b8-000d3a367d35</p>
      
      <p>target incident id: 8491c0df-0df4-e911-a813-000d3a33f11e target title:
      20191021 10:12a target raised on: 10/21/2019 2:20:08 PM traget local
      time now:  10/21/2019 2:20:08 PM Before retrieveMultiple After
      retrieveMultiple In foreach loop oldest incidentid:
      74e2f090-0df4-e911-a813-000d3a33f11e Title: 20191021 10:12a Master
      Ticket Guid: 74e2f090-0df4-e911-a813-000d3a33f11e oldest Raised On:
      10/21/2019 2:17:58 PM Total Record Count: 2 1 record(s) matching.
      Timespan is 0.00150799356481481 days greather than original ticket
      (less than 30 days). Ticket will be merged with original ticket.
      Merging 8491c0df-0df4-e911-a813-000d3a33f11e into
      74e2f090-0df4-e911-a813-000d3a33f11e.</p>
      
      <p> </p>
    </blockquote>
  </blockquote>