title: Search with SharePoint CSOM (portable) throws an exception
body: <p>I am trying to use SharePoint client framework to execute a search, using the portable dll's from a Windows app. </p>
  
  <p>Using Fiddler I can see that my search is executed, and returns a JSON collection of metadata and search results. This is identical to the result from the non-portable CSOM.</p>
  
  <p>When CSOM tries to map the result to it's data objects I get the following exception:</p>
  
  <blockquote>
    <p>Unable to cast object of type 'System.Collections.Generic.Dictionary`2[System.String,System.Object]' to type 'Microsoft.SharePoint.Client.Search.Query.ResultTableCollection'.</p>
  </blockquote>
  
  <p>This exception occurs inside CSOM (portable). Non-portable CSOM runs without exception, and returns the expected result.</p>
  
  <p>The code I am running to get this exception is:</p>
  
  <pre><code>var query = new KeywordQuery(ctx);
  query.QueryText = "something";
  var executor = new SearchExecutor(ctx);
  var results = executor.ExecuteQuery(query);
  await ctx.ExecuteQueryAsync();
  </code></pre>
  
  <p>In the above, ctx is a ClientContext that has already been authenticated. Other requests, such as getting a specific list, works as expected.</p>
  
  <p>I am referencing the following dll's from c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI:</p>
  
  <ul>
  <li>Microsoft.SharePoint.Client.Portable.dll</li>
  <li>Microsoft.SharePoint.Client.Runtime.Portable.dll</li>
  <li>Microsoft.SharePoint.Client.Runtime.WindowsStore.dll</li>
  <li>Microsoft.SharePoint.Client.Search.Portable.dll</li>
  </ul>
  
  <p>My question is.</p>
  
  <p>How do I solve this, so that I can use CSOM to run search queries from a Windows Store app?</p>
  
  <p>UPDATE:
  I added the following after authenticating the ClientContext:</p>
  
  <pre><code>ctx.ExecutingWebRequest += (s, e) =&gt;
      e.WebRequest.Headers["Accept-Encoding"] = "gzip, deflate";
  </code></pre>
  
  <p>This solved the immediate problem, but introduced a new one. I am now getting a System.FormatException:</p>
  
  <blockquote>
    <p>Not well formatted JSON stream.</p>
  </blockquote>
  
  <p>Since the JSON from portable and non-portable CSOM is the same, there should not be a parsing error in one CSOM and not the other.</p>