Skip to main content

How to Resolve Error "CS0123: No overload for 'method' matches delegate 'delegate'" in C#

The Compiler Error CS0123 is a Signature Mismatch error. The message reads: "No overload for 'MethodName' matches delegate 'DelegateName'".

In C#, a Delegate defines a specific contract for a function signature (its return type and its parameters). When you attempt to assign a method to a delegate (or subscribe a method to an event), that method must look exactly how the delegate expects it to look. If the return types differ, or the parameters don't match in count or type, the compiler raises CS0123.

This guide explains how to identify the mismatch and align your method signatures.

Understanding Delegate Signatures

A delegate declaration acts like a template.

// The Template: Returns void, takes one string.
public delegate void LogHandler(string message);

To assign a method to LogHandler, that method generally must:

  1. Return void.
  2. Take exactly one parameter.
  3. That parameter must be a string.

If you try to assign void MyMethod(int number), the compiler rejects it because it cannot pass a string (from the delegate) into an int (expected by the method).

Scenario 1: Parameter Count or Type Mismatch

This is the most common cause. You created a method intended to handle the delegate, but you changed the arguments in one place and forgot to update the other.

Example of error

public delegate void Calculator(int x, int y);

public class Program
{
// ⛔️ Error: Wrong parameter types (double vs int)
public static void AddDoubles(double x, double y)
{
System.Console.WriteLine(x + y);
}

// ⛔️ Error: Wrong parameter count (1 vs 2)
public static void AddSingle(int x)
{
System.Console.WriteLine(x + 10);
}

static void Main()
{
// CS0123: No overload for 'AddDoubles' matches delegate 'Calculator'
Calculator calc1 = AddDoubles;

// CS0123: No overload for 'AddSingle' matches delegate 'Calculator'
Calculator calc2 = AddSingle;
}
}

Solution: Match the Parameters

You must ensure the method signature matches the delegate definition exactly.

public delegate void Calculator(int x, int y);

public class Program
{
// ✅ Correct: Takes exactly two integers, matching the delegate.
public static void AddIntegers(int x, int y)
{
System.Console.WriteLine(x + y);
}

static void Main()
{
Calculator calc = AddIntegers;
calc(5, 10);
}
}

Output:

15

Scenario 2: Return Type Mismatch

The method must return the same type of data that the delegate expects to return. You cannot assign a method that returns int to a delegate that is defined as void (returning nothing), or vice versa.

Example of error

// Delegate expects an integer return value
public delegate int NumberProvider();

public class Program
{
// ⛔️ Error: This method returns 'void' (nothing).
public static void GetNothing()
{
System.Console.WriteLine("Returning nothing");
}

static void Main()
{
// CS0123: No overload for 'GetNothing' matches delegate 'NumberProvider'
NumberProvider provider = GetNothing;
}
}

Solution

Change the method to return int, or change the delegate to return void.

public delegate int NumberProvider();

public class Program
{
// ✅ Correct: Returns int
public static int GetNumber()
{
return 42;
}

static void Main()
{
NumberProvider provider = GetNumber;
int result = provider();
}
}

Scenario 3: Standard Event Handler Mistakes

This error frequently frustrates developers working with WinForms, WPF, or ASP.NET events. Standard C# events usually rely on the EventHandler delegate, which requires two specific parameters: object sender and EventArgs e.

If you try to wire up a simple method that takes no parameters (because you don't plan to use sender or e), CS0123 triggers.

Example of error

using System;

public class Button
{
public event EventHandler Click;
}

public class Form
{
public void Initialize()
{
Button btn = new Button();

// ⛔️ Error CS0123: 'OnButtonClick' does not look like an EventHandler.
// EventHandler expects (object, EventArgs).
btn.Click += OnButtonClick;
}

public void OnButtonClick()
{
Console.WriteLine("Clicked");
}
}

Solution

Add the required parameters, even if you don't use them.

public class Form
{
public void Initialize()
{
Button btn = new Button();

// ✅ Correct: Signature matches standard EventHandler
btn.Click += OnButtonClick;
}

// Parameters added to match signature
public void OnButtonClick(object sender, EventArgs e)
{
Console.WriteLine("Clicked");
}
}
tip

Lambda Shortcut: If you don't want to write the full method definition, you can use a lambda expression that ignores the parameters: btn.Click += (s, e) => Console.WriteLine("Clicked");

Conclusion

CS0123 is a strict type-safety check.

  1. Check the Declaration: Right-click the Delegate or Event name and select "Go to Definition". Look at what it expects.
  2. Check the Method: Look at the method you are trying to assign.
  3. Compare: Do the parameter types match perfectly? Does the return type match?
  4. Fix: Modify your method to align with the delegate's requirements.