C# Compiler Error
CS0123 – No overload for ‘method’ matches delegate ‘delegate’
Reason for the Error
This C# error will occur when you try to create a delegate in C# with in-correct signature.
For example, try compiling the below code snippet.
namespace DeveloperPublishNamespace { delegate void Delegate1(); public class DeveloperPublish { public static void function1(int i) { } public static void Main() { // Error because function1 takes an integer parameter while the delegate Delegate1 doesnot Delegate1 d = new Delegate1(function1); } } }
We have declared a delegate without a parameter and when we create an instance by passing a function with a different signature, you will see the below error.
Error CS0123 No overload for ‘function1’ matches delegate ‘Delegate1’ ConsoleApp1 C:\Users\Senthil\source\repos\ConsoleApp1\ConsoleApp1\Program.cs 11 Active
If you are on .NET Mono, the error might look something like this
error CS0123: A method or delegate DeveloperPublishNamespace.DeveloperPublish.function1(int)' parameters do not match delegate
DeveloperPublishNamespace.Delegate1()’ parameters
Solution
You can avoid this error by changing the access modifier of the Method to allow its access (if needed).