0
votes

I have this very short custom helper

using System.Web.Mvc;

namespace Colibri.HtmlHelpers
{
    public static class CustomHelper
    {
        public static MvcHtmlString SearchBar(this HtmlHelper helper, string type)
        {
            return new MvcHtmlString("<input type=\"text\" placeholder =\"Recherche...\" id=\"" + type + "-Search\" class=\"Search-Input\"/>");
        }
    }
}

In the Razor Web.config I added the namespace in the proper section:

<add namespace="Colibri.HtmlHelpers" />

An I just want to call it from a view with this code:

@Html.SearchBar("Article")

Here I get this error:

Error CS0121 The call is ambiguous between the following methods or properties: 'Colibri.HtmlHelpers.CustomHelper.SearchBar(System.Web.Mvc.HtmlHelper, string)' and 'Colibri.HtmlHelpers.CustomHelper.SearchBar(System.Web.Mvc.HtmlHelper, string)'

If I don't add the namespace in Web.config, it says:

Error CS1061 'HtmlHelper' does not contain a definition for 'SearchBar' and no extension method 'SearchBar' accepting a first argument of type 'HtmlHelper' could be found (are you missing a using directive or an assembly reference?)

Thanks for your help.

1
No, it's got nothing to do with different namespaces - it's just you've got the same method signature declared in two places. Try searching SearchBar method in whole project and check.Rahul Nikate
CS0121 usually appears when 2 assemblies, classes or methods with different version exist in a project. Use full namespace or change method's name if you think naming conflict is behind the issue.Tetsuya Yamamoto
I already checked for that, assuming I forget I did something with the same name a long time ago, but no. It's really the same reference. And when I call the method, it shows me the same signature twice. Quite weird.Julien
I tried Fully qualified name; I I get this error: Error CS0433 The type 'Julien' exists in both 'Colibri, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' and 'App_Code.vmsvzsyo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' ColibriJulien

1 Answers

0
votes

Thanks all for your help.

I found out the issue: I just moved the .cs file from App_Code directory to another one.

It works fine now.