Web Api controller thinks it is duplicated

I have a webforms application that has some Web Api controllers for integration. Two are working fine. But today I wanted to add another controller.

It should be simple enough, I add a new Web Api controller, add some code to it and:

namespace MyApp.Web.App_Code
{
    public class AuthExportController : ApiController
    {
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }
    }
 }

and when I call it at this URL:

http://localhost:30978/MyApp/api/AuthExport

I get this error:

<Error>
    <Message>An error has occurred.</Message>
    <ExceptionMessage>Multiple types were found that match the controller named  
    'AuthExport'. This can happen if the route that services this request  
    ('api/{controller}/{id}') found multiple controllers defined with the same name but 
    differing namespaces, which is not supported. The request for 'AuthExport' has found 
    the following matching controllers: MyApp.Web.App_Code.AuthExportController  
    MyApp.Web.App_Code.AuthExportController</ExceptionMessage>

    <ExceptionType>System.InvalidOperationException</ExceptionType>

    <StackTrace> at  
    System.Web.Http.Dispatcher.DefaultHttpControllerSelector.SelectController(HttpRequestMessag
    e request) at   
    System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncInternal(HttpRequestMessage 
    request, CancellationToken cancellationToken) at 
    System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsync(HttpRequestMessage  
    request, CancellationToken cancellationToken)</StackTrace>
</Error>

As you can see, it complains about 2 controllers with the same name, but has the same controller. My other controllers are working fine, only this one is specific.

If this helps, this is my routing code in global.asax

protected void Application_Start(object sender, EventArgs e)
{
    RouteTable.Routes.MapHttpRoute(
        name: "DefaultApi",
        routeTemplate: "api/{controller}/{id}",
        defaults: new { id = System.Web.Http.RouteParameter.Optional }
    );

    GlobalConfiguration.Configuration.Formatters.Clear();
    GlobalConfiguration.Configuration.Formatters.Add(new XmlMediaTypeFormatter());
}

You are crazy!

Update:

, , , , , - . . , , , .. .. , , - . "", "". "", .

, :) , ,

+5
2

TL; DR:

bin .

:

, :

, FirstName SecondName.

  • , bin/Debug/FirstName.dll
  • SecondName
  • bin/Debug/SecondName.dll

, IIS Express .dll , FirstName.dll SecondName.dll.

, , , FirstName.dll SecondName.dll , ! , DLL IIS, WebApi .

. :)

+25

, , . , , /bin , , . , bin , . , :

  • //
  • /bin, /bin/debug

  • /obj/debug/(.dll,.cache, ) .

, , . /bin , .

0

Source: https://habr.com/ru/post/1546266/


All Articles