title: HttpActionContext.get_Request() method not found when using Microsoft Asp.NET Dependency Injection
body: <p>I am trying to add <a href="https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection/" rel="nofollow noreferrer">Microsoft Extensions Dependency Injection</a> to an existing ASP.NET WebApi/Owin project.</p>
  
  <p>Following <a href="https://scottdorman.github.io/2016/03/17/integrating-asp.net-core-dependency-injection-in-mvc-4/" rel="nofollow noreferrer">this blog post</a>, I have added the <code>ConfigureServices</code> function, implemented <code>DependencyResolver</code>, and made <code>HttpConfiguration</code> instance to use it.</p>
  
  <p>Also I added all the non-abstract controllers to DI, and ensured they are instantiated using the DI mechanism.</p>
  
  <p>But after all these actions, requests to the application return error 500 with exception</p>
  
  <blockquote>
    <p>Method not found: 'System.Net.Http.HttpRequestMessage System.Web.Http.Controllers.HttpActionContext.get_Request()'.</p>
  </blockquote>
  
  <p>I get the same result even if I just add the <code>Microsoft.Extensions.DependencyInjection</code> package to NuGet and don't change any other code. After I remove it, everything works fine.</p>
  
  <p>Here is the code I added into Startup.cs:</p>
  
  <p>The DependcyResolver implementation:</p>
  
  <pre><code>public class DefaultDependencyResolver :
      System.Web.Http.Dependencies.IDependencyResolver, 
      System.Web.Http.Dependencies.IDependencyScope
  {
      protected IServiceProvider serviceProvider;
  
      public DefaultDependencyResolver(IServiceProvider serviceProvider)
      {
          this.serviceProvider = serviceProvider;
      }
  
      public IDependencyScope BeginScope()
      {
          return this;
      }
  
      public void Dispose() { }
  
      public object GetService(Type serviceType)
      {
          return this.serviceProvider.GetService(serviceType);
      }
  
      public IEnumerable&lt;object&gt; GetServices(Type serviceType)
      {
          return this.serviceProvider.GetServices(serviceType);
      }
  
  }
  </code></pre>
  
  <p>Adding controllers to DI:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      System.Diagnostics.Debugger.Launch();   
      IEnumerable&lt;Type&gt; controllers = typeof(Startup).Assembly.GetExportedTypes()
         .Where(t =&gt; !t.IsAbstract &amp;&amp; !t.IsGenericTypeDefinition)
         .Where(t =&gt; typeof(IController).IsAssignableFrom(t)
            || t.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase));
  
      foreach (var c in controllers)
      {
          services.AddTransient(c);
      }
  }
  </code></pre>
  
  <p>Creating ServiceCollection, calling services configuration and setting DependencyResolver:</p>
  
  <pre><code>public void Configuration(IAppBuilder app) {
      // ...
      HttpConfiguration httpConfiguration = new HttpConfiguration();
  
      var services = new ServiceCollection();
      ConfigureServices(services);
  
      httpConfiguration.DependencyResolver = 
          new DefaultDependencyResolver(services.BuildServiceProvider());
  
      WebApiConfig.Register(httpConfiguration);
      app.UseWebApi(httpConfiguration);
  }
  </code></pre>
  
  <p>The exception stacktrace:</p>
  
  <pre><code>at myCompany.myProduct.Controllers.SomeController.Get(String id, String offline)
  at lambda_method(Closure , Object , Object[] )
  at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.&lt;&gt;c__DisplayClass10.&lt;GetExecutor&gt;b__9(Object instance, Object[] methodParameters)
  at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
  System.Web.Http.Controllers.ApiControllerActionInvoker.&lt;InvokeActionAsyncCore&gt;d__0.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.&lt;ExecuteAsync&gt;d__2.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at System.Web.Http.Dispatcher.HttpControllerDispatcher.&lt;SendAsync&gt;d__1.MoveNext()
  </code></pre>