title: "Unexpected Response Code for Operation: 0" when executing Azure Table Storage batch delete
body: <p>I'm using version 4.3.0 of the Windows Azure Storage libraries for .NET. In my ATS repository class, I have a couple of batch delete methods that look like this:</p>
  
  <pre><code>public async Task DeleteAsync(IEnumerable&lt;T&gt; entities)
  {
      await ExecuteAsBatch(entities, (batch, entity) =&gt; batch.Delete(entity));
  }
  
  private async Task ExecuteAsBatch(IEnumerable&lt;T&gt; entities, Action&lt;TableBatchOperation, T&gt; batchAction)
  {
      var byPartition = entities.GroupBy(x =&gt; x.PartitionKey).ToList();
  
      await byPartition.ForEachParallel(async group =&gt;
      {
          // A maximum of 100 actions are allowed per batch job
          var segments = group.ToList().ToSegmentedList(100);
          await segments.ForEachParallel(async segment =&gt;
          {
              var batch = new TableBatchOperation();
              foreach (var entity in segment)
              {
                  batchAction(batch, entity);
              }
              await Table.ExecuteBatchAsync(batch);
          }, 10);
      }, 10);
  }
  </code></pre>
  
  <p>In other places in my code, that <code>DeleteAsync()</code> method works correctly. However, in one particular place, I get this error message when executing the batch:</p>
  
  <pre><code>Unexpected Response Code for Operation: 0
  </code></pre>
  
  <p>Here's the call site:</p>
  
  <pre><code>private async Task MergeAtsOrganizationUserEvents(int organizationId, IEnumerable&lt;CustomerUserEvent&gt; fromEvents, CustomerUser to)
  {
      var toDelete = (await fromEvents.SelectParallel(async fromEvent =&gt;
      {
          var pkey = AtsOrganizationUserEventByMinute.GetPartitionKey(organizationId, fromEvent.OccurredOn);
          var rkey = AtsOrganizationUserEventByMinute.GetRowKey(fromEvent.OccurredOn, fromEvent.CustomerUserEventId);
          return await Ats.OrganizationUserEventByMinute.FindByPartitionRowAsync(pkey, rkey);
      })).Where(x =&gt; x != null).ToList();
  
      var toInsert = toDelete
          .Select(x =&gt; AtsOrganizationUserEventByMinute.FromBase(x.OrganizationId, x.OccurredOn, x.CookieId,
              to.CustomerUserId, x))
          .ToList();
  
      try
      {
          await Ats.OrganizationUserEventByMinute.UpsertAsync(toInsert);
          await Ats.OrganizationUserEventByMinute.DeleteAsync(toDelete);
      }
      catch (Exception ex)
      {
          _logger.Error("Unable to merge {0} AtsOrganizationEvents for org {1}, to customer user {2}: {3}",
              toInsert.Count, organizationId, to.CustomerUserId, ex.CompleteMessage());
          throw;
      }
  }
  </code></pre>
  
  <p>The <code>UpsertAsync()</code> method above succeeds, but the <code>DeleteAsync()</code> fails. Note that it fails to delete precisely the same entities that <code>FindByPartitionRowAsync()</code> retrieved from the table, so I can't quite imagine how it could have anything to do with malformed entities or anything of that ilk.</p>
  
  <p>Here's an example of one of the "toDelete" objects (in JSON format):</p>
  
  <pre><code>{  
     "CookieId":null,
     "CustomerUserId":185766,
     "CustomerUserEventId":3568687,
     "OrganizationId":4190,
     "EventName":"event1",
     "SessionId":null,
     "OccurredOn":"2014-10-20T18:17:09.9971379Z",
     "UrlId":null,
     "Url":null,
     "ReferrerUrlId":null,
     "ReferrerUrl":null,
     "IsSynthetic":false,
     "IpAddress":null,
     "PartitionKey":"4190.2014.10.20",
     "RowKey":"18.17.3568687",
     "Timestamp":"2014-10-20T18:17:11.237+00:00",
     "ETag":"W/\\"   datetime'2014-10-20T18%3A17%3A11.237Z'\\""
  }
  </code></pre>
  
  <p>Azure Storage error messages are notoriously and spectacularly unhelpful, and Googling has returned nothing about batch deletes failing with this particular error.</p>
  
  <p>This fails both when using local development storage and in production.</p>
  
  <p>Any thoughts?</p>