title: Web-API Versioning not working with Default version
body: <p>I created one web API application with versioning. I am going to use <code>Microsoft.AspNet.WebApi.Versioning</code> package to do that.</p>
  
  <p>Webapi configuration:</p>
  
  <pre><code>public static class WebApiConfig
  {
      public static void Register(HttpConfiguration config)
      {
          // Web API configuration and services
          config.AddApiVersioning(o =&gt; {
              o.AssumeDefaultVersionWhenUnspecified = true;
          });
          // Web API routes
          config.MapHttpAttributeRoutes();
  
      }
  }
  </code></pre>
  
  <p>Here my assumption is if I didn't pass the version, by default it will select version 1.</p>
  
  <p>Controller code:</p>
  
  <pre><code>[ApiVersion("1.0")]
  [RoutePrefix("api/users")]
  public class UserV1Controller : BaseController
  {
      public UserV1Controller()
      {
      }
  
      [Route("all", Name = "UsersCollection")]
      public async Task&lt;IHttpActionResult&gt; GetAll()
      {
          var items = await UnitOfWork.Users.GetPaged(x =&gt; x.OrderBy(y =&gt; y.Id), 1, 20);
          //Add mapping to DTO 
          return Ok(items);
      }
  
  }
  </code></pre>
  
  <p>If I test with <code>http://localhost:10280/api/users/all?api-version=1.0</code> URL, it working fine. I am going to implement this feature in the existing project.</p>
  
  <p>For backward compatibility, I tried <code>http://localhost:10280/api/users/all</code> URL.
  It gives me the following error with <strong>500</strong> as the status code.</p>
  
  <blockquote>
    <p>{
    "Message": "An error has occurred.",<br/>
    "ExceptionMessage": "The index cannot be less than 0 or equal to or larger than the number of items in the collection.\r\n<br/>Parameter
    name: index\r\nActual value was 0.",<br/>
        "ExceptionType": "System.ArgumentOutOfRangeException",<br/>
        "StackTrace": "   at <br/>System.Web.Http.WebHost.Routing.HostedHttpRouteCollection.get_Item(Int32
    index)\r\n   at
    Microsoft.Web.Http.Dispatcher.ApiVersionControllerSelector.GetControllerName(HttpRequestMessage
    request)\r\n   at
    Microsoft.Web.Http.Dispatcher.ControllerSelectionContext.&lt;>c__DisplayClass6_0.&lt;.ctor>b__0()\r\n
    at System.Lazy<code>1.CreateValue()\r\n   at
    System.Lazy</code>1.LazyInitValue()\r\n   at System.Lazy`1.get_Value()\r\n<br>
    at
    Microsoft.Web.Http.Dispatcher.ConventionRouteControllerSelector.SelectController(ControllerSelectionContext
    context)\r\n   at
    Microsoft.Web.Http.Dispatcher.ApiVersionControllerSelector.SelectController(HttpRequestMessage
    request)\r\n   at
    System.Web.Http.Dispatcher.HttpControllerDispatcher.d__15.MoveNext()"
    }</p>
  </blockquote>
  
  <hr>
  
  <p><strong>Update 1:</strong></p>
  
  <p>After discussions and a bit of help, I can confirm that this default version works with conventional routing. </p>
  
  <p>The issue reproduced while using attribute routing. Please check my updated code.</p>
  
  <ol>
  <li>I don't have any default API routing in the WebAPIConfig file. </li>
  <li>I update Route Prefix and Route in the controller</li>
  </ol>
  
  <p>Now the issue reproduced. </p>
  
  <p>You can also reproduce the issue with combining conventional and attribute. </p>
  
  <h1>Update 2:</h1>
  
  <p>Now I noticed that the issue lies in the configuration. If I add the routing configurations in the Owin startup class directly it working fine. </p>
  
  <pre><code>    public partial class Startup
  {
      public void Configuration(IAppBuilder app)
      {
          ConfigureAuth(app);
          var configuration = new System.Web.Http.HttpConfiguration();
          var httpServer = new System.Web.Http.HttpServer(configuration);
  
          // reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
          configuration.AddApiVersioning(options =&gt;
          {
              options.ReportApiVersions = true;
              options.AssumeDefaultVersionWhenUnspecified = true;
          });
          configuration.MapHttpAttributeRoutes();
          app.UseWebApi(httpServer);
  
      }
  }
  </code></pre>
  
  <p>It creates new <strong><em>HttpConfiugration</em></strong> other than using our existing WebAPIConfig class. So I don't know it may impact any other functionalities</p>
  
  <p>So if i configure Owin to use webaPI instead of <strong><em>GlobalConfiguration.Configure(WebApiConfig.Register)</em></strong> in the Global.asax, it iw working fine.</p>