Azure table storage error: "Unexpected response code for operation : 99"
This un-descriptive error means that Azure bulk operations (at least in this case) takes up to 100 elements. Limit your batch and you'll be good.
I ended up using something like this:
public void Insert(IEnumerable<T> entities)
{
foreach (var chunk in entities.Chunk(100))
{
InsertMaxLimitElements(chunk);
}
}
private void InsertMaxLimitElements(IEnumerable<T> chunk)
{
var insert = new TableBatchOperation();
foreach (var entity in chunk)
{
insert.Insert(entity);
}
cloudTable.ExecuteBatch(insert);
}
The Chunk extension method was copied from this answer:
public static IEnumerable<IEnumerable<T>> Chunk<T>(this IEnumerable<T> source, int chunksize)
{
while (source.Any())
{
yield return source.Take(chunksize);
source = source.Skip(chunksize);
}
}