Compiler error CS0121

The call is ambiguous between the following methods or properties: 'method1' and 'method2'

Due to implicit conversion, the compiler was not able to call one form of an overloaded method. You can resolve this error in one of the following ways:

  • Specify the method parameters in such a way that implicit conversion does not take place.
  • Remove all overloads for the method.
  • Cast to proper type before calling the method.
  • Use named arguments.

Example 1

The following examples generate compiler error CS0121:

public class Program
{
    static void f(int i, double d)
    {
    }

    static void f(double d, int i)
    {
    }

    public static void Main()
    {
        f(1, 1);   // CS0121

        // Try the following code instead:
        // f(1, 1.0);
        // or
        // f(1.0, 1);
        // or
        // f(1, (double)1);   // Cast and specify which method to call.
        // or
        // f(i: 1, 1);
        // or
        // f(d: 1, 1);

        // f(i: 1, d: 1); // This still gives CS0121
    }
}

Example 2

class Program2
{
    static int ol_invoked = 0;

    delegate int D1(int x);
    delegate T D1<T>(T x);
    delegate T D1<T, U>(U u);

    static void F(D1 d1) { ol_invoked = 1; }
    static void F<T>(D1<T> d1t) { ol_invoked = 2; }
    static void F<T, U>(D1<T, U> d1t) { ol_invoked = 3; }

    static int Test001()
    {
        F(delegate(int x) { return 1; }); // CS0121
        if (ol_invoked == 1)
            return 0;
        else
            return 1;
    }

    static int Main()
    {
        return Test001();
    }
}