Skip to main content

How to Resolve Error "CS0856: Indexed property has non-optional arguments which must be provided" in C#

The Compiler Error CS0856 is a syntax error related to Indexed Properties, a feature primarily found in COM Interop (like Microsoft Office automation) or libraries written in languages like VB.NET. The message reads: "Indexed property 'Property' has non-optional arguments which must be provided".

Standard C# properties (obj.Prop) do not take arguments. C# indexers (obj[i]) take arguments but have no name. However, COM objects often have properties that have names AND arguments (e.g., Range["A1"]). This error occurs when you try to access such a property using simple property syntax (obj.Range) without providing the required arguments in brackets.

Understanding Indexed Properties

In standard C#, you access a property like this:

  • myObj.Value (No arguments).

In COM/VB.NET, a property can be defined like this (pseudo-code):

  • Property Range(cell As String) As Range

To access this in C#, you must provide the argument cell. The compiler treats this special property like a C# Indexer, but with a name.

  • Correct C# Syntax: myObj.Range["A1"]

If you write myObj.Range, the compiler sees that arguments are required but missing, triggering CS0856.

Scenario: Missing Arguments on COM Properties

This error is almost exclusively encountered when automating Excel, Word, or using other COM libraries.

Example of error

You try to access the property as if it were a standard C# property, ignoring the parameters it demands.

// Pseudo-interface for Excel Worksheet
public interface IWorksheet
{
// A named indexed property requiring two arguments
string Cells[int row, int column] { get; set; }
}

public class ExcelAutomation
{
public void ReadData(IWorksheet sheet)
{
// ⛔️ Error CS0856: Indexed property 'Cells' has non-optional arguments
// which must be provided.
// You cannot refer to 'Cells' without saying WHICH cell.
var data = sheet.Cells;
}
}

Solution: Provide Arguments in Brackets

You must supply the required arguments using square brackets [] immediately after the property name.

public class ExcelAutomation
{
public void ReadData(IWorksheet sheet)
{
// ✅ Correct: Providing the Row and Column arguments.
var data = sheet.Cells[1, 1];

System.Console.WriteLine(data);
}
}
note

Optional Arguments: Some COM properties have optional arguments. If all arguments are optional, C# allows you to omit the brackets entirely (e.g., app.Workbooks works even if it technically accepts arguments). CS0856 only triggers when at least one argument is mandatory (non-optional).

Conclusion

CS0856 acts as a reminder that the property you are accessing acts like a function requiring inputs.

  1. Identify the Property: Look at the name in the error message (e.g., Cells, Range, Item).
  2. Check Documentation: Verify how many arguments the COM object expects for that property.
  3. Add Brackets: Append [arg1, arg2] to the property call.