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

Recommended Answers

All 2 Replies

Did you put a copy of your code into the GAC?

You could be getting the error at run time because of the way dynamic compilation works in ASP.NET.

The only two things I can think of is that either you have two declarations of it in two different extension classes in the same namespace, or, an old library is being linked into the application that shouldn't be (the compiler won't pick this up).

If you do a solution search for GetTLD(this string str) you should be able to see if you have a double declaration. Otherwise, rename the extension here GetTopLevelDomain (wordy but a good name). If it fixes it straight away, rename it back again and delete EVERYTHING from the bin and obj folders of every project in your solution and then do a full rebuild.

If it still doesn't fix it, you definitely have a double declaration somewhere.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.