dotnet/orleans · error · ArgumentOutOfRangeException

Data too large to write to table. Size={0} MaxSize={1}

Error message

Data too large to write to table. Size={0} MaxSize={1}

What it means

Thrown by StateEntity.CheckMaxDataSize when the serialized transactional state exceeds the maximum permitted size for a single table entity (and its chunked string-data properties). Azure Table entities are limited; Orleans chunks the payload but caps total size.

Source

Thrown at src/Azure/Orleans.Transactions.AzureStorage/TransactionalState/StateEntity.cs:156

                            yield return data;
                        }
                    }
                }
            }
        }

        private object? GetPropertyOrDefault(string key)
        {
            this.Entity.TryGetValue(key, out var result);
            return result;
        }

        private static void CheckMaxDataSize(int dataSize, int maxDataSize)
        {
            if (dataSize > maxDataSize)
            {
                var msg = string.Format("Data too large to write to table. Size={0} MaxSize={1}", dataSize, maxDataSize);
                throw new ArgumentOutOfRangeException("state", msg);
            }
        }

        private static IEnumerable<string> GetPropertyNames()
        {
            yield return STRING_DATA_PROPERTY_NAME_PREFIX;
            for (var i = 1; i < MAX_DATA_CHUNKS_COUNT; ++i)
            {
                yield return STRING_DATA_PROPERTY_NAME_PREFIX + i.ToString(CultureInfo.InvariantCulture);
            }
        }
    }
}

View on GitHub (pinned to fca799fa70)

Solutions

  1. Reduce the size of the grain state: prune collections, archive large fields to Blob Storage and store only a reference.
  2. Split the grain so each activation holds less state.
  3. Move large payloads out of transactional state into non-transactional storage keyed by grain id.

Example fix

// before
public class CartState { public List<Item> Items = new(); } // grows unbounded

// after
public class CartState { public int ItemCount; public string BlobRef; } // items archived to blob
Defensive patterns

Strategy: validation

Validate before calling

if (serializedState.Length > MaxStateSize) throw new InvalidOperationException("grain state too large; archive to blob");

Try / catch

try { await storage.Store(...); }
catch (ArgumentOutOfRangeException ex) when (ex.Message.Contains("Data too large"))
{ /* archive payload, store reference, retry */ }

Prevention

When it happens

Trigger: A grain's TState grows large enough that its serialized form plus chunking overhead exceeds maxDataSize at write time.

Common situations: Unbounded collections stored in transactional grain state; large blobs embedded in state; a grain accumulating history without compaction.

Related errors


AI-assisted analysis of dotnet/orleans@fca799fa70 (2026-08-13). Data as JSON: /api/errors/81843eb104f6aee9. Report an issue: GitHub.