Skip to main content

How to Resolve Error "CS0839: Argument missing" in C#

The Compiler Error CS0839 is a syntax error caused by incomplete method calls or definitions. The message reads: "Argument missing".

This error occurs when the compiler encounters an empty spot in your code where it expects a value, a variable, or an expression. This is almost always caused by an extra comma , inside a list of arguments, parameters, or array initializers, creating a "ghost" slot that contains nothing.

This guide explains how to spot these typos and correct your syntax.

Understanding the Syntax Rule

In C#, the comma , is a separator. It strictly means: "There is an item before me, and there is an item after me."

  • Valid: Method(a, b)
  • Invalid: Method(a, , b)

If you place two commas side-by-side (,,), or leave a comma trailing without a closing brace in contexts that don't support it, the compiler sees an empty space and reports that an argument is missing from that space.

Scenario 1: Extra Commas in Method Calls

This is the most frequent cause. It often happens when deleting an argument but forgetting to delete the comma that separated it.

Example of error

public class Logger
{
public static void Log(string a, string b) { }

public static void Run()
{
// ⛔️ Error CS0839: Argument missing.
// The compiler sees: "Argument 1: 'Hello'", "Argument 2: [MISSING]", "Argument 3: 'World'".
Log("Hello", , "World");
}
}

Solution: Remove the Comma

Simply delete the extra comma so the arguments form a continuous list.

public class Logger
{
public static void Log(string a, string b) { }

public static void Run()
{
// ✅ Correct: No empty slots.
Log("Hello", "World");
}
}

Scenario 2: Extra Commas in Method Definitions

This error also applies when defining a method. If you leave a trailing comma or a double comma in the parameter list, the compiler thinks you intended to declare another parameter but forgot to type it.

Example of error

public class Calculator
{
// ⛔️ Error CS0839: Argument missing.
// The compiler expects a type and name after the comma.
public void Add(int x, int y, )
{
}
}

Solution: Clean the Parameter List

Remove the trailing comma.

public class Calculator
{
// ✅ Correct
public void Add(int x, int y)
{
}
}

Scenario 3: Missing Values in Array Initializers

While C# allows trailing commas in array initializers (e.g., { 1, 2, } is valid), it does not allow empty slots in the middle of the list.

Example of error

public class Data
{
public void Load()
{
// ⛔️ Error CS0839: Argument missing.
// You cannot skip an index in an array initializer.
int[] numbers = { 1, 2, , 4 };
}
}

Solution: Fill or Remove

Either provide a value for that slot or remove the comma.

public class Data
{
public void Load()
{
// ✅ Correct: Remove the gap
int[] numbers = { 1, 2, 4 };

// OR provide a default value
int[] numbers2 = { 1, 2, 0, 4 };
}
}
note

Trailing Commas: C# does allow a single trailing comma at the end of an array or object initializer to make copy-pasting easier: var x = new[] { 1, 2, 3, }; // This is valid. var x = new[] { 1, , 3 }; // This raises CS0839.

Conclusion

CS0839 is purely a typo checker.

  1. Check for ,,: Look for two commas next to each other.
  2. Check for , ): Look for a comma immediately followed by a closing parenthesis in a method call or definition.
  3. The Fix: Delete the extra comma.