C# Error CS0123 – No overload for ‘method’ matches delegate ‘delegate’

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

C# Error CS0123 – No overload for 'method' matches delegate 'delegate'

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 delegateDeveloperPublishNamespace.Delegate1()’ parameters

Solution

You can avoid this error by changing the access modifier of the Method to allow its access (if needed).

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...