The call is ambiguous between single method i.e extension method

shashwat picture shashwat · Jun 24, 2013 · Viewed 9.2k times · Source

I have an extension method like

public static class Extension
{
    public static string GetTLD(this string str)
    {
        var host = new System.Uri(str).Host;
        int index = host.LastIndexOf('.'), last = 3;
        while (index >= last - 3)
        {
            last = index;
            index = host.LastIndexOf('.', last - 1);
        }
        var domain = host.Substring(index + 1);
        return domain;
    }
}

And I am calling this like

string domain = "." + _url.GetTLD();

I am getting no error at building and clean build.
But I am getting compilation error at run time error saying

The call is ambiguous between the following methods or properties: 'myIGNOU.Extension.GetTLD(string)' and 'myIGNOU.Extension.GetTLD(string)'

I swear that I don't have this extension method placed any where else too in the project. Why I am getting this error only at run time..?

But if I delete this method then I am getting error at build time not not at run time. Everything works fine without the code of this method.

Here is compilation error page

Answer

Danielku15 picture Danielku15 · Sep 24, 2013

I had the same problem but for me it solved the problem to remove the own project from the project references. Resharper accidentally added a reference to the compiled binary of the same project. That way I had the same extension class 2 times within my project. During building it couldn't distinguish between the source-version or the binary-version of the extension class.

So basically: Check your project references if it contains a reference to itself.

Answer provided by @shashwat is also a case.