Index zero based must be greater than or equal to zero
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
The error "Index (zero based) must be greater than or equal to zero and less than the size of the argument list" is a .NET FormatException (or ArgumentOutOfRangeException) that occurs when using string.Format(), composite formatting, or collection indexing with an invalid index. It means you are referencing a placeholder like {2} but only provided 2 arguments (indices 0 and 1), or you are accessing a negative index in a collection.
The Error in String Formatting
The most common trigger is a mismatch between placeholders and arguments in string.Format():
Why It Happens
string.Format uses zero-based indexing for placeholders:
{0}→ first argument{1}→ second argument{2}→ third argument
If the highest placeholder index is {N}, you need at least N + 1 arguments.
Common Causes
Cause 1: Missing Arguments
Cause 2: Wrong Placeholder Index
Cause 3: Curly Braces in Text
Cause 4: Console.WriteLine and Similar Methods
Cause 5: String Interpolation Migration
When converting from string.Format to interpolated strings, leftover placeholders cause issues:
The Error in Collection Indexing
The same concept applies to list/array access:
Prevention with String Interpolation
Modern C# (6.0+) eliminates most formatting errors with string interpolation:
Debugging Tips
Common Pitfalls
- Dynamic format strings: When the format string comes from a database, config file, or resource file, the argument count may not match. Always validate dynamic format strings.
- Localization: Translated strings may have different placeholder counts than the original. Ensure all translations maintain the same placeholders.
- Logging frameworks: Libraries like NLog and Serilog use similar
{0}syntax. A mismatch between template placeholders and arguments causes the same error. - Off-by-one: Forgetting that indices start at 0, not 1.
{1}is the second argument, not the first. - Escaped braces: To include a literal
{or}in a format string, double it:{{or}}. A single{without a valid index triggers aFormatException.
Summary
- The error occurs when a format placeholder references an index that does not have a corresponding argument
{0}is zero-based —{N}requires at leastN + 1arguments- Use string interpolation (
$"...") in C# 6+ to avoid index mismatch entirely - Escape literal curly braces with
{{and}} - Validate format strings from external sources (databases, config files, translations)
- For collection indexing, always check
index >= 0 && index < countbefore access
Related reading
- Indexing on nested field
- Indexing ranked permutations into other ranked permutations
- Infinite flux and bulk-write to database
- Infinite Recursion with Jackson JSON and Hibernate JPA issue
- Infinite loop in EventQueue.isDispatchThread
- Infinite recursion in JavaScript quicksort?
- INNER JOIN ON vs WHERE clause
- INNER JOIN ON vs WHERE clause

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.