title: How do I get an Mvc 5 Controller's ActionDescriptor when using Attribute Routing?
body: <p>I am trying to get get an <strong>ActionDescriptor</strong> for an action on a controller that uses <strong>Attribute Routing</strong>, however it is always null.</p>
  
  <pre><code>var controllerDescriptor = new ReflectedControllerDescriptor(controllerType);
  var actionDescriptor = 
      controllerDescriptor.FindAction(controllerContext, actionName) ??
      controllerDescriptor.GetCanonicalActions().FirstOrDefault(a =&gt; a.ActionName == actionName);
  </code></pre>
  
  <p>From my research, I have found that in the class <strong>ActionMethodSelectorBase</strong> there is a method called <strong>PopulateLookupTables</strong> which splits up all of the methods in the controller that you give it. Inside thie method there it filters the list of MethodInfo's into 2 sets of lists.</p>
  
  <ul>
  <li><strong>AliasedMethods</strong> - All action methods with no direct routes that are decorated with the ActionNameSelectorAttribute.</li>
  <li><strong>NonAliasedMethods</strong> - All action methods with no direct routes that are not decorated with the ActionNameSelectorAttribute.</li>
  </ul>
  
  <p><em>NOTE: The AliasedMethods and NonAliasedMethods will be empty if a direct route (RouteAttribute) is set at the controller level.</em></p>
  
  <p><em>NOTE: Direct Routes are defined as methods that are in a controller (excluding constructors and events) and are decorated with an attribute that inherits from either IRouteInfoProvider or IDirectRouteFactory (RouteAttribute inherits from both of these).</em></p>
  
  <p>and</p>
  
  <ul>
  <li><strong>DirectRouteMethods</strong> - Methods with some form of IRouteInfoProvider decorating them directly.</li>
  <li><strong>StandardRouteMethods</strong> - Methods with no IRouteInfoProvider decorating them directly. (includes action methods in a controller with RouteAttribute but where the method does not have a RouteAttribute).</li>
  </ul>
  
  <p>When <strong>ReflectedControllerDescriptor.FindAction</strong> is called, it internally calls <strong>ActionMethodSelectorBase.FindActionMethods</strong> which only looks at the <strong>AliasedMethods</strong> and <strong>NonAliasedMethods</strong> (which exclude all actions with direct routes).</p>
  
  <p>When <strong>ReflectedControllerDescriptor.GetCanonicalActions</strong> is called, it internally calls <strong>ReflectedControllerDescriptor.GetAllActionMethodsFromSelector</strong> which only looks at the <strong>AliasedMethods</strong> and <strong>NonAliasedMethods</strong> (which exlude all actions with direct routes).</p>
  
  <p>From what I can see, the <strong>DirectRouteMethods</strong> are only used in one place, the <strong>RouteCollection.MapMvcAttributeRoutes</strong> extention methods. This means that the <strong>RouteTable.Routes</strong> collection has a <strong>RouteCollectionRoute</strong> to the action but I am not sure how to get to it.</p>
  
  <p>Does anyone know how to get an <strong>ActionDescriptor</strong> for an action that has a <strong>RouteAttribute</strong></p>