title: Web API Controller Method -- Request is null
body: <p>When calling the method shown below, Request is always null.  I have some simple methods returning JSON data from controllers in an MVC4 app with controllers using ApiController as a base class.  The code for my directory function is as follows:</p>
  
  <pre><code>public HttpResponseMessage GetDirectory() {
          try {
              var dir = r.GetDirectory();
              if (dir == null) {
                  throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError));
              }
              var response = Request.CreateResponse(HttpStatusCode.OK, dir, "application/json");
              response.Headers.Location = new Uri(Request.RequestUri, "directory");
              return response;
          } catch (Exception ex) {
              return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
          }
      }
  </code></pre>
  
  <p>When this method is called, 'dir' is loaded properly from r.GetDirectory(). But Request is null. So naturally Request.CreateResponse() fails, and so on.  I am looking for reasons why Request would be null, or for a rewrite that allows the return to remain an  HttpResponseMessage.</p>
  
  <p>This is being called (in my unit test project) with:</p>
  
  <pre><code>var ctrl = new DirectoryController();
  var httpDir = ctrl.GetDirectory();
  </code></pre>
  
  <p>Thanks for your help.</p>