title: Downloading file fails on the second download
body: <p>I have the following code using CSOM to download a file from a sharepoint site:</p>
  
  <pre><code>    public IEnumerable&lt;FileUpload&gt; DownloadFiles(string client, Guid userGuid, IEnumerable&lt;Guid&gt; fileUploadGuids)
      {
          using (var context = new ClientContext(documentStore))
          {
              client = client.ToLower();
  
              var result = IntialSetUp(client, userGuid, fileUploadGuids, context);
  
              context.Load(result, items =&gt; items.Include(
                  item =&gt; item.File.Name,
                  item =&gt; item[FileTitle],
                  item =&gt; item[FileRef]
              ));
  
              context.ExecuteQuery();
  
              List&lt;FileUpload&gt; fileUploads = new List&lt;FileUpload&gt;();
  
              foreach (var item in result)
              {
                  using (var fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, item[FileRef].ToString()))
                  {
                      using (var memory = new MemoryStream())
                      {
                          fileInfo.Stream.CopyTo(memory);
  
                          fileUploads.Add(new FileUpload()
                          {
                              Name = item[FileTitle].ToString(),
                              FileUploadGuid = new Guid(item.File.Name),
                              FileBytes = memory.ToArray()
                          });
                      }
                  }
              }
  
              return fileUploads;
          }
      }
  
      public  void AddNetworkCredentials(ClientContext context)
      {
          string login = ConfigurationManager.AppSettings["UserName"];
          string password = ConfigurationManager.AppSettings["Password"];
  
          context.Credentials = new NetworkCredential(login, password, ConfigurationManager.AppSettings["Domain"]);
  
          context.ExecuteQuery();
      }
  
      public ListItemCollection IntialSetUp(string client, Guid userGuid, IEnumerable&lt;Guid&gt; fileUploadGuids, ClientContext context)
      {
          AddNetworkCredentials(context);
  
          var list = context.Web.Lists.GetByTitle(client);
  
          context.ExecuteQuery();
  
          return GetItems(FileLeafRef, Array.ConvertAll(fileUploadGuids.ToArray(), x =&gt; x.ToString("N")), list, FieldType.File, documentStore + "/" + client + "/" + userGuid.ToString("N"));
      }
  </code></pre>
  
  <p>This code will run fine the first time round, but every consecutive request will throw the following error:</p>
  
  <pre><code>The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
  </code></pre>
  
  <p>This only happens for this service request and doesn't effect other requests that do not download the actual file, this leads me to believe it has something to do with the OpenBinaryDirect method but I haven't found anything describing this issue.</p>
  
  <p>Any ideas as to what might be causing this and how it could be remedied?</p>
  
  <p>notes:</p>
  
  <ul>
  <li>Left in a bunch of ExecteQuerys for testing purposes. </li>
  <li>The title of    the file is actually a guid so we could have multiple
  files with the    same name (the file name is a separate column)</li>
  </ul>