locked
Wrong operation index in execute batch exception RRS feed

  • Question

  • I am getting an operation index that is out of bounds of the array when executing a batch operation on Windows Azure Tables.

    Exception
    <quote>Exception: Microsoft.WindowsAzure.Storage.StorageException: Unexpected response code for operation : 0<br>
      at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.EndExecuteAsync[T](IAsyncResult result)
    Request Information<br>
    RequestID:e31dbcbc-8dc2-46ba-b096-9872b34072cb<br>
    RequestDate:Sun, 15 Sep 2013 10:41:10 GMT<br>
    StatusMessage:Accepted<br>
    ErrorCode:InvalidInput<br>
    ErrorMessage= 68:One of the request inputs is not valid.<br>
    batchOperation.Count= 68</quote>

    As you can see from the error message above, the failed operation index is 68 (zero based) while the total count of operations in the batch is 68 (so the maximum index is 67).

    Why is this happening and how can I avoid it?

    Thank you,
    Sunday, September 15, 2013 11:02 AM

Answers

  • I did 2 things:

    1. I upgraded the WindowsAzure.Storage API to version 2.1.0.0
    2. I changed the code to look as follows
     public static Task<IList<TableResult>> ExecuteBatchAsync(
                this CloudTable table,
                TableBatchOperation batchOperation, 
                bool isInsertOrReplace = false, bool isInsertOrMerge = false, bool isDelete = false,
                CancellationToken cancellationToken = default (CancellationToken))
            {
                _log.Source = _logSource;
                ICancellableAsyncResult asyncResult = table.BeginExecuteBatch(batchOperation, null, null);
                CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null);
    
                return Task<IList<TableResult>>.Factory.FromAsync(
                    asyncResult,
                    result =>
                    {
                        try
                        {
                            registration.Dispose();
                            table.ServiceClient.RetryPolicy = new ExponentialRetry(TimeSpan.FromMilliseconds(15), 10);
                            return table.EndExecuteBatch(result);
                        }
                        catch (StorageException ex)
                        {
                            lock (ex)
                            {
                                if (ex.RequestInformation.ExtendedErrorInformation != null)
                                {
                                    string errorMessage = ex.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                    int index = errorMessage.IndexOf(":");
                                    int resultIndex = -1; Int32.TryParse(errorMessage.Substring(0, index).Trim(), out resultIndex);
                                    if (resultIndex >= batchOperation.Count && batchOperation.Count > 0) resultIndex = 0;
                                    if (isInsertOrReplace && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation insertOrReplaceOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(insertOrReplaceOperation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during InsertOrReplace operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during InsertOrReplace operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (isInsertOrMerge && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation insertOrMergeOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(insertOrMergeOperation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during InsertOrMerge operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during InsertOrMerge operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (isDelete && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation deleteOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(deleteOperation);
                                        }
                                        catch (StorageException ex2)
                                        {
                                            errorMessage = ex2.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            if (!ex2.RequestInformation.ExtendedErrorInformation.ErrorCode.Equals("ResourceNotFound"))
                                            {
                                                _log.WriteEntry(String.Format("Error during Delete operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                    table.Name, ex2.ToString().Length > 32700 ? ex2.ToString().Substring(0, 32700) : ex2.ToString(), errorMessage, ex2.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                            }
                                        }
                                        catch (Exception ex2)
                                        {
                                            _log.WriteEntry("Error during Delete operation on table \"" + table.Name + "\".\r\nException: " + (ex2.ToString().Length > 32700 ? ex2.ToString().Substring(0,32700) : ex2.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation operation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(operation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else
                                    {
                                        _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nbatchOperation.Count= {3}, resultIndex= {4}, RequestID= {5}",
                                            table.Name, ex.ToString().Length > 32700 ? ex.ToString().Substring(0, 32700) : ex.ToString(), errorMessage, batchOperation.Count, resultIndex, ex.RequestInformation.ServiceRequestID),
                                            System.Diagnostics.EventLogEntryType.Error);                                    
                                    }
                                    if (resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        batchOperation.RemoveAt(resultIndex);
                                        return table.ExecuteBatch(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete);
                                    }
                                    return null;
                                }
                                else
                                {
                                    try
                                    {
                                        return table.ExecuteBatch(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete);
                                    }
                                    catch (Exception ex1)
                                    {
                                        _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}",
                                            table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        return null;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            lock (ex)
                            {
                                try
                                {
                                    return table.ExecuteBatch(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete);
                                }
                                catch (Exception ex1)
                                {
                                    _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}",
                                        table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                    return null;
                                }
                            }
                        }
                    });
            }

    So far, the inconsistent operation index did not occur again.

    Tuesday, September 17, 2013 10:48 AM

All replies

  • hi Youssef,

    Thanks for posting!
    From your description, I guess you may need pay attention to the format of Table Service Data Model and the rule of name. Please double check your data configuration and name follow this article: http://msdn.microsoft.com/en-us/library/dd179338.aspx. And about this question, I think you may like those solutions and articles:
    http://blogs.msdn.com/b/cesardelatorre/archive/2011/03/12/typical-issue-one-of-the-request-inputs-is-not-valid-when-working-with-the-wa-development-storage.aspx
    http://deeperdesign.wordpress.com/2010/03/10/azure-table-storage-what-a-pain-in-the-ass/
    http://blogs.breeze.net/scotts/2011/01/25/WindowsAzureTableStorageWoesOneOfTheRequestInputsIsNotValid.aspx
    In order for me to better understand your problem please post some code.
    Thanks.


    Will
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 16, 2013 10:02 AM
  • Thank you for your response.

    Here is the code I use to execute a batch and handle the exceptions:

    public static Task<IList<TableResult>> ExecuteBatchAsync(
                this CloudTable table,
                TableBatchOperation batchOperation,
                bool isInsertOrReplace = false, bool isInsertOrMerge = false, bool isDelete = false,
                CancellationToken cancellationToken = default (CancellationToken))
            {
                _log.Source = _logSource;
                ICancellableAsyncResult asyncResult = table.BeginExecuteBatch(batchOperation, null, null);
                CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null);
    
                return Task<IList<TableResult>>.Factory.FromAsync(
                    asyncResult,
                    result =>
                    {
                        try
                        {
                            registration.Dispose();
                            table.ServiceClient.RetryPolicy = new ExponentialRetry(TimeSpan.FromMilliseconds(15), 10);
                            return table.EndExecuteBatch(result);
                        }
                        catch (StorageException ex)
                        {
                            lock (ex)
                            {
                                if (ex.RequestInformation.ExtendedErrorInformation != null)
                                {
                                    string errorMessage = ex.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                    int index = errorMessage.IndexOf(":");
                                    int resultIndex = -1; Int32.TryParse(errorMessage.Substring(0, index).Trim(), out resultIndex);
                                    if (resultIndex >= batchOperation.Count && batchOperation.Count > 0) resultIndex = 0;
                                    if (isInsertOrReplace && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation insertOrReplaceOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(insertOrReplaceOperation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during InsertOrReplace operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during InsertOrReplace operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (isInsertOrMerge && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation insertOrMergeOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(insertOrMergeOperation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during InsertOrMerge operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during InsertOrMerge operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (isDelete && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation deleteOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(deleteOperation);
                                        }
                                        catch (StorageException ex2)
                                        {
                                            errorMessage = ex2.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            if (!ex2.RequestInformation.ExtendedErrorInformation.ErrorCode.Equals("ResourceNotFound"))
                                            {
                                                _log.WriteEntry(String.Format("Error during Delete operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                    table.Name, ex2.ToString().Length > 32700 ? ex2.ToString().Substring(0, 32700) : ex2.ToString(), errorMessage, ex2.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                            }
                                        }
                                        catch (Exception ex2)
                                        {
                                            _log.WriteEntry("Error during Delete operation on table \"" + table.Name + "\".\r\nException: " + (ex2.ToString().Length > 32700 ? ex2.ToString().Substring(0,32700) : ex2.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation operation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(operation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else
                                    {
                                        _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nbatchOperation.Count= {3}, resultIndex= {4}, RequestID= {5}",
                                            table.Name, ex.ToString().Length > 32700 ? ex.ToString().Substring(0, 32700) : ex.ToString(), errorMessage, batchOperation.Count, resultIndex, ex.RequestInformation.ServiceRequestID),
                                            System.Diagnostics.EventLogEntryType.Error);                                    
                                    }
                                    if (resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        batchOperation.RemoveAt(resultIndex);
                                        return table.ExecuteBatchAsync(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete, cancellationToken).Result;
                                    }
                                    return null;
                                }
                                else
                                {
                                    try
                                    {
                                        return table.ExecuteBatchAsync(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete, cancellationToken).Result;
                                    }
                                    catch (Exception ex1)
                                    {
                                        _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}",
                                            table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        return null;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            lock (ex)
                            {
                                try
                                {
                                    return table.ExecuteBatchAsync(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete, cancellationToken).Result;
                                }
                                catch (Exception ex1)
                                {
                                    _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}",
                                        table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                    return null;
                                }
                            }
                        }
                    });
            }

    I am following the guidelines for the table names, restrictions on field sizes and number of properties. The code works for some cases and handles the exceptions properly when the reported operation index in the ErrorMessage is within the valid range. I have added a statement above to set the operation index to zero when it is out of range.

    Notice the anomaly in the exception details. The Storage exception says Unexpected response code for operation : 0. While the ErrorMessage in the extended error information says 68.

    Monday, September 16, 2013 10:57 AM
  • hi,

    I want to test your code, but your code sample may lack some needed method.

    But from your code logic and error message, I think your  "remove" method condition may be error.I think it shold be this:

    if (resultIndex >= 0 && resultIndex < batchOperation.Count&&batchOperation.Count>0)
    {
         batchOperation.RemoveAt(resultIndex);
         return table.ExecuteBatchAsync(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete, cancellationToken).Result;
                                    }
     

    I think you may need to judge the "batchOperation.Count". please try it

    thanks

    • Edited by Billgiee Tuesday, September 17, 2013 9:54 AM
    Tuesday, September 17, 2013 9:54 AM
  • The RemoveAt method is part of the API for TableBatchOperation class.
    Tuesday, September 17, 2013 9:56 AM
  • Do you get this error when your code run last one? I think your can add "batchOperation.Count" condition in your "if" judge. And you use this judgemnet code condition twice:

    else if (resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation operation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(operation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else
                                    {
                                        _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nbatchOperation.Count= {3}, resultIndex= {4}, RequestID= {5}",
                                            table.Name, ex.ToString().Length > 32700 ? ex.ToString().Substring(0, 32700) : ex.ToString(), errorMessage, batchOperation.Count, resultIndex, ex.RequestInformation.ServiceRequestID),
                                            System.Diagnostics.EventLogEntryType.Error);                                    
                                    }
                                    if (resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        batchOperation.RemoveAt(resultIndex);
                                        return table.ExecuteBatchAsync(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete, cancellationToken).Result;
                                    }
    please modify it and try it.

    • Edited by Billgiee Tuesday, September 17, 2013 10:03 AM
    Tuesday, September 17, 2013 10:02 AM
  • I did 2 things:

    1. I upgraded the WindowsAzure.Storage API to version 2.1.0.0
    2. I changed the code to look as follows
     public static Task<IList<TableResult>> ExecuteBatchAsync(
                this CloudTable table,
                TableBatchOperation batchOperation, 
                bool isInsertOrReplace = false, bool isInsertOrMerge = false, bool isDelete = false,
                CancellationToken cancellationToken = default (CancellationToken))
            {
                _log.Source = _logSource;
                ICancellableAsyncResult asyncResult = table.BeginExecuteBatch(batchOperation, null, null);
                CancellationTokenRegistration registration = cancellationToken.Register(p => asyncResult.Cancel(), null);
    
                return Task<IList<TableResult>>.Factory.FromAsync(
                    asyncResult,
                    result =>
                    {
                        try
                        {
                            registration.Dispose();
                            table.ServiceClient.RetryPolicy = new ExponentialRetry(TimeSpan.FromMilliseconds(15), 10);
                            return table.EndExecuteBatch(result);
                        }
                        catch (StorageException ex)
                        {
                            lock (ex)
                            {
                                if (ex.RequestInformation.ExtendedErrorInformation != null)
                                {
                                    string errorMessage = ex.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                    int index = errorMessage.IndexOf(":");
                                    int resultIndex = -1; Int32.TryParse(errorMessage.Substring(0, index).Trim(), out resultIndex);
                                    if (resultIndex >= batchOperation.Count && batchOperation.Count > 0) resultIndex = 0;
                                    if (isInsertOrReplace && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation insertOrReplaceOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(insertOrReplaceOperation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during InsertOrReplace operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during InsertOrReplace operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (isInsertOrMerge && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation insertOrMergeOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(insertOrMergeOperation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during InsertOrMerge operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during InsertOrMerge operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (isDelete && resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation deleteOperation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(deleteOperation);
                                        }
                                        catch (StorageException ex2)
                                        {
                                            errorMessage = ex2.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            if (!ex2.RequestInformation.ExtendedErrorInformation.ErrorCode.Equals("ResourceNotFound"))
                                            {
                                                _log.WriteEntry(String.Format("Error during Delete operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                    table.Name, ex2.ToString().Length > 32700 ? ex2.ToString().Substring(0, 32700) : ex2.ToString(), errorMessage, ex2.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                            }
                                        }
                                        catch (Exception ex2)
                                        {
                                            _log.WriteEntry("Error during Delete operation on table \"" + table.Name + "\".\r\nException: " + (ex2.ToString().Length > 32700 ? ex2.ToString().Substring(0,32700) : ex2.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else if (resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        try
                                        {
                                            TableOperation operation = batchOperation[resultIndex];
                                            TableResult r = table.Execute(operation);
                                        }
                                        catch (StorageException ex1)
                                        {
                                            errorMessage = ex1.RequestInformation.ExtendedErrorInformation.ErrorMessage;
                                            _log.WriteEntry(String.Format("Error during operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nRequestID= {3}",
                                                table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString(), errorMessage, ex1.RequestInformation.ServiceRequestID), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                        catch (Exception ex1)
                                        {
                                            _log.WriteEntry("Error during operation on table \"" + table.Name + "\".\r\nException: " + (ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        }
                                    }
                                    else
                                    {
                                        _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}ErrorMessage= {2},\r\nbatchOperation.Count= {3}, resultIndex= {4}, RequestID= {5}",
                                            table.Name, ex.ToString().Length > 32700 ? ex.ToString().Substring(0, 32700) : ex.ToString(), errorMessage, batchOperation.Count, resultIndex, ex.RequestInformation.ServiceRequestID),
                                            System.Diagnostics.EventLogEntryType.Error);                                    
                                    }
                                    if (resultIndex >= 0 && resultIndex < batchOperation.Count)
                                    {
                                        batchOperation.RemoveAt(resultIndex);
                                        return table.ExecuteBatch(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete);
                                    }
                                    return null;
                                }
                                else
                                {
                                    try
                                    {
                                        return table.ExecuteBatch(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete);
                                    }
                                    catch (Exception ex1)
                                    {
                                        _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}",
                                            table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0, 32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                        return null;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            lock (ex)
                            {
                                try
                                {
                                    return table.ExecuteBatch(batchOperation, isInsertOrReplace, isInsertOrMerge, isDelete);
                                }
                                catch (Exception ex1)
                                {
                                    _log.WriteEntry(String.Format("Error during ExecuteBatch operation on table \"{0}\".\r\nException: {1}",
                                        table.Name, ex1.ToString().Length > 32700 ? ex1.ToString().Substring(0,32700) : ex1.ToString()), System.Diagnostics.EventLogEntryType.Error);
                                    return null;
                                }
                            }
                        }
                    });
            }

    So far, the inconsistent operation index did not occur again.

    Tuesday, September 17, 2013 10:48 AM