Question

I can't figure out why I'm getting this error. I only have one class with one method in my project that looks like:

public static class Extensions
{
    public static string Chop(this string s, int length)
    {
        ...
        return "";
    }
}

I'm calling this in my View like so: @item.PostContent.Chop(20)
It's giving me a compiler error:

The call is ambiguous between the following methods or properties: 'Extensions.Chop(string, int)' and 'Extensions.Chop(string, int)'

Any help is appreciated. Thank you.

Was it helpful?

Solution

I'm guessing that you have put your Extensions class file in an App_Code folder, is that correct? If so, move it outside of App_Code and get rid of the folder. App_Code has no place in MVC applications which by default are created as Web Application projects as opposed to Web Site projects.

Web Applications are compiled to a dll at build time, and anything in App_Code is also compiled into a separate dll at run time. Hence there being two methods and the ambiguity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top