title: Why is my Web API call returning "No action was found on the controller 'DPlatypus' that matches the request"?
body: <p>I am trying to create the simplest possible ASP.NET Web API app that incorporates and uses DI with Castle Windsor.</p>
  
  <p>I have a working app that is more complicated, and I have tried to copy the "bare bones" from it (as little as possible and still have it work).</p>
  
  <p>The working app has this URL ("Home Page"): </p>
  
  <pre><code>http://localhost:28642/
  </code></pre>
  
  <p>Entering this:</p>
  
  <pre><code>http://shannon2:28642/api/Departments/Count
  </code></pre>
  
  <p>...in my browser returns the data I want, from the Departments Controller.</p>
  
  <p>However, the new/simple/non-working app has this URL ("Home Page"): </p>
  
  <pre><code>http://localhost:33181/
  </code></pre>
  
  <p>...and entering this: </p>
  
  <pre><code>http://localhost:33181/api/DPlatypus/4
  </code></pre>
  
  <p>...does NOT return the data I want:</p>
  
  <p>In fact, this:</p>
  
  <pre><code>`http://shannon2:33181/api/DPlatypus/4` 
  </code></pre>
  
  <p>...returns:</p>
  
  <p><em>Bad Request - Invalid Hostname
  HTTP Error 400. The request hostname is invalid.</em></p>
  
  <p>While the URI previously shown (<code>http://localhost:33181/api/DPlatypus/4</code>) returns:</p>
  
  <pre><code>This XML file does not appear to have any style information associated with it. The document tree is shown below.
  &lt;Error&gt;
  &lt;Message&gt;
  No HTTP resource was found that matches the request URI `'http://localhost:33181/api/DPlatypus/4'.`
  &lt;/Message&gt;
  &lt;MessageDetail&gt;
  No action was found on the controller 'DPlatypus' that matches the request.
  &lt;/MessageDetail&gt;
  &lt;/Error&gt;
  &lt;/MessageDetail&gt;
  &lt;/Error&gt;
  </code></pre>
  
  <p>But I <em>do</em> have an action that should match the request, namely:</p>
  
  <pre><code>public class DPlatypusController : ApiController
  {
      private readonly IDPlatypusRepository _duckbillRepository;
  
      public DPlatypusController(IDPlatypusRepository duckbillRepository)
      {
          if (duckbillRepository == null)
          {
              throw new ArgumentNullException("duckbillRepository is null");
          }
          _duckbillRepository = duckbillRepository;
      }
  
      [Route("api/DPlatypus")]
      public string GetDPlatypusNameById(int Id)
      {
          return _duckbillRepository.Get(Id);
      }
  
  }
  </code></pre>
  
  <p>Here is the Repository class:</p>
  
  <pre><code>public class DPlatypusRepository : IDPlatypusRepository
  {
      private List&lt;DPlatypus&gt; platypi = new List&lt;DPlatypus&gt;();
      private int _nextId = 1;
  
      public DPlatypusRepository()
      {
          Add(new DPlatypus { Name = "Donald" });
          Add(new DPlatypus { Name = "GoGo" });
          Add(new DPlatypus { Name = "Patty" });
          Add(new DPlatypus { Name = "Platypup" });
          Add(new DPlatypus { Name = "Platypop" });
          Add(new DPlatypus { Name = "Platymop" });
          Add(new DPlatypus { Name = "Platydude" });
          Add(new DPlatypus { Name = "Platydudette" });
      }
  
      public IEnumerable&lt;DPlatypus&gt; GetAll()
      {
          return platypi;
      }
  
      public String Get(int id)
      {
          return platypi.Find(p =&gt; p.Id == id).Name;
      }
  
      public DPlatypus Add(DPlatypus platypus)
      {
          if (platypus == null)
          {
              throw new ArgumentNullException("platypus");
          }
          platypus.Id = _nextId++;
          platypi.Add(platypus);
          return platypus;
      }
  }
  </code></pre>
  
  <p>I am registering/installing in WindsorDependencyResolver.cs, I have altered Global.asax, and WebApiConfig.cs, so that they are just like the working app, yet...no go. Why might this be?</p>
  
  <h2>UPDATE</h2>
  
  <p>For M. Mimpen, here is Global.asax:</p>
  
  <pre><code>namespace WebApplication4
  {
      public class WebApiApplication : System.Web.HttpApplication
      {
          private static IWindsorContainer _container;
          protected void Application_Start()
          {
              ConfigureWindsor(GlobalConfiguration.Configuration);
              GlobalConfiguration.Configure(c =&gt; WebApiConfig.Register(c, _container));
  
              FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
              RouteConfig.RegisterRoutes(RouteTable.Routes);
              BundleConfig.RegisterBundles(BundleTable.Bundles);
          }
  
          public static void ConfigureWindsor(HttpConfiguration configuration)
          {
              _container = new WindsorContainer();
              _container.Install(FromAssembly.This());
              _container.Kernel.Resolver.AddSubResolver(new CollectionResolver(_container.Kernel, true));
              var dependencyResolver = new WindsorDependencyResolver(_container);
              configuration.DependencyResolver = dependencyResolver;
          }
  
          protected void Application_End()
          {
              _container.Dispose();
              base.Dispose();
          }
  
      }
  }
  </code></pre>
  
  <h2>UPDATE 2</h2>
  
  <p>For Kiran Challa; now I get:</p>
  
  <pre><code>This XML file does not appear to have any style information associated with it. The document tree is shown below.
  &lt;Error&gt;
  &lt;Message&gt;
  No HTTP resource was found that matches the request URI 'http://localhost:33181/api/DPlatypus?id=4'.
  &lt;/Message&gt;
  &lt;MessageDetail&gt;
  No action was found on the controller 'DPlatypus' that matches the request.
  &lt;/MessageDetail&gt;
  &lt;/Error&gt;
  </code></pre>