title: ASP.net web api 2 error "The parameters dictionary contains a null entry for parameter"
body: <p>I have routes configured like this: </p>
  
  <pre><code>   routes.MapHttpRoute("DefaultApi2", "api/{controller}/{action}/{id}", new {id = RouteParameter.Optional}
  </code></pre>
  
  <p>And My controller looks like this:</p>
  
  <pre><code>  public class RoutineController : ApiController
  {
      private readonly RoutineService _routineService;
  
      public RoutineController(RoutineService routineService)
      {
          _routineService = routineService;
      }
  
  
  
      [HttpGet]
      [ActionName("Tags")]
      public List&lt;RoutineTag&gt; Tags()
      {
          return _routineService.GetAllTags();
      }
  
      [HttpGet]
      [ActionName("SingleRoutine")]
      // GET api/routine/5
      public RoutineViewModel SingleRoutine(int id)
      {
          return _routineService.GetRoutineById(id);
  
      }
  }
  </code></pre>
  
  <p>But I'm getting this error:</p>
  
  <pre><code>{"Message":"The request is invalid.","MessageDetail":"The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'Infrastructure.Api.Models.RoutineViewModel Routine(Int32)' in 'Infrastructure.Api.Controllers.RoutineController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter."}
  </code></pre>
  
  <p>If I change method SingleRoutine to this:</p>
  
  <pre><code>    [HttpGet]
      [ActionName("SingleRoutine")]
      // GET api/routine/5
      public RoutineViewModel SingleRoutine(int? id)
      {
          if (!id.HasValue)
          {
              return null;
          }
          return _routineService.GetRoutineById((int) id);
  }
  </code></pre>
  
  <p>In browser I just see "null".</p>
  
  <p>Why is this happening ?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This error is shown when I type /api/routine/tags</p>