How to Resolve Error "CS0316: The parameter name 'name' conflicts with an automatically-generated parameter name" in C#
The Compiler Error CS0316 is a Naming Collision error reserved for implicit parameter names. The message reads: "The parameter name 'value' conflicts with an automatically-generated parameter name."
In C# Indexers and Property Setters, the compiler automatically generates a hidden parameter named value to represent the incoming data being assigned. If you manually define a parameter in an indexer's signature and name it value, you create a collision with this hidden system parameter. The compiler doesn't know if value refers to the index argument you declared or the data being assigned.
This guide explains where the hidden value comes from and how to avoid this conflict.
Understanding the 'value' Parameter
When you define an indexer:
public string this[int index]
{
set { /* ... */ }
}
The set accessor is compiled into a method that looks roughly like this:
public void set_Item(int index, string value) { ... }
index: Comes from your parameter list[int index].value: Is automatically generated to hold the data from the right-hand side of the assignment (obj[0] = "data").
If you name your index parameter value, the generated method signature would become:
public void set_Item(string value, string value)
This is invalid C# (duplicate parameter names), causing CS0316.
Scenario: Indexer Parameter Collision
This error happens almost exclusively when creating custom indexers (like a dictionary or array wrapper) and accidentally using the name value for the lookup key.
Example of error:
public class DictionaryWrapper
{
private string[] _data = new string[10];
// ⛔️ Error CS0316: The parameter name 'value' conflicts with an automatically-generated parameter name.
// In the 'set' block, 'value' refers to the incoming string being assigned.
// But here, we also named the index integer 'value'.
public string this[int value]
{
get { return _data[value]; }
set { _data[value] = value; } // Which 'value' is which?
}
}
Solution: Rename the Parameter
Since the implicit parameter name value cannot be changed (it is part of the C# language specification for setters), you must rename your explicit parameter.
Standard conventions for indexer parameters are index, key, i, or descriptive names like userId.
Solution: rename the integer parameter to index.
public class DictionaryWrapper
{
private string[] _data = new string[10];
// ✅ Correct: Renamed 'value' to 'index'.
public string this[int index]
{
get
{
return _data[index];
}
set
{
// Now unambiguous:
// 'index' is the position (int).
// 'value' is the assigned data (string, implicit).
_data[index] = value;
}
}
}
Conclusion
CS0316 protects the functionality of property setters and indexers.
- Identify the Context: Are you writing an Indexer
this[...]? - Check Parameters: Did you name one of the inputs
value? - Rename: Change your parameter name to
index,key, oridto avoid clashing with the keywordvalue.