title: CRM 2011 - Error in advance search on PhoneCall entity
body: <p>I am facing problem in Advance Search of PhoneCall Entity on my test environment (but the same is on the production environment). I am not using English version, so instead of screenshots I'll describe everything.</p>
  
  <p>Trying to find all PhoneCalls with defined not-null ToRecipent.</p>
  
  <p>Download FetchXML:</p>
  
  <pre><code>&lt;fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true"&gt;
    &lt;entity name="phonecall"&gt;
      &lt;attribute name="subject" /&gt;
      &lt;attribute name="statecode" /&gt;
      &lt;attribute name="prioritycode" /&gt;
      &lt;attribute name="scheduledend" /&gt;
      &lt;attribute name="regardingobjectid" /&gt;
      &lt;attribute name="rlpl_status" /&gt;
      &lt;attribute name="directioncode" /&gt;
      &lt;attribute name="phonenumber" /&gt;
      &lt;attribute name="ownerid" /&gt;
      &lt;attribute name="to" /&gt;
      &lt;order attribute="subject" descending="false" /&gt;
      &lt;link-entity name="activityparty" from="activityid" to="activityid" alias="aa"&gt;
        &lt;filter type="and"&gt;
          &lt;condition attribute="participationtypemask" operator="eq" value="2" /&gt;
          &lt;condition attribute="partyid" operator="not-null" /&gt;
        &lt;/filter&gt;
      &lt;/link-entity&gt;
    &lt;/entity&gt;
  &lt;/fetch&gt;
  </code></pre>
  
  <p>Instead of results I can see standard Unexpected Error on site. I have run the CRM 2011 Diagnostic tool to get a read out of what is happening there and found this exception after select statement:</p>
  
  <pre><code>Microsoft.Crm.Extensibility.InternalOperationPlugin, Microsoft.Crm.ObjectModel, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35; ClassName: Microsoft.Crm.Extensibility.InternalOperationPlugin; Exception: Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
     at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct&amp; sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
     at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
     at System.Web.Services.Protocols.LogicalMethodInfo.Invoke(Object target, Object[] values)
     at Microsoft.Crm.Extensibility.InternalOperationPlugin.Execute(IServiceProvider serviceProvider)
     at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
     at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
  Inner Exception: System.NullReferenceException: Object reference not set to an instance of an object.
     at Microsoft.Crm.ObjectModel.CommunicationActivityServiceBase.RetrieveMultiple(EntityExpression entityExpression, ExecutionContext context)
  </code></pre>
  
  <p>I executed the same query on database and it returned results successfully. It looks like CRM has problem with loading and converting this information.
  I found the same bug in Advance Search of Phonecall Entity with 2 others custom link-entities, but the rest looks fine.</p>
  
  <p>What is more...
  I deleted ToRecipent column from Advance Search and the results showed up, but I can't open any of them no matter how many times I click on them.</p>
  
  <p>Download FetchXML:</p>
  
  <pre><code>&lt;fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true"&gt;
    &lt;entity name="phonecall"&gt;
      &lt;attribute name="subject" /&gt;
      &lt;attribute name="statecode" /&gt;
      &lt;attribute name="prioritycode" /&gt;
      &lt;attribute name="scheduledend" /&gt;
      &lt;attribute name="regardingobjectid" /&gt;
      &lt;attribute name="rlpl_status" /&gt;
      &lt;attribute name="directioncode" /&gt;
      &lt;attribute name="phonenumber" /&gt;
      &lt;attribute name="ownerid" /&gt;
      &lt;order attribute="subject" descending="false" /&gt;
      &lt;link-entity name="activityparty" from="activityid" to="activityid" alias="ab"&gt;
        &lt;filter type="and"&gt;
          &lt;condition attribute="participationtypemask" operator="eq" value="2" /&gt;
          &lt;condition attribute="partyid" operator="not-null" /&gt;
        &lt;/filter&gt;
      &lt;/link-entity&gt;
    &lt;/entity&gt;
  &lt;/fetch&gt;
  </code></pre>
  
  <p>I even deleted all Phonecalls except one to make sure it isn't related with corrupted test data. Still Exception appeared. What's wrong?</p>