title: Asp.Net: No suitable Constructor for AuthenticationMiddleware
body: <p>I'm currently trying to write an AuthenticationMiddleware. See <a href="https://stackoverflow.com/a/31688792/1171404">this answer</a>. The app builds with no error but when I execute <code>dnx web</code> I get the following error:</p>
  
  <blockquote>
    <p>Unable to locate suitable constructor for type 'Namespace.BasicAuthenticationMiddleware'. Ensure the type is concrete and all parameters are accepted by a constructor.</p>
    
    <p>at Microsoft.Extensions.Internal.ActivatorUtilities.CreateInstance(IServiceProvider
     provider, Type instanceType, Object[] parameters)</p>
    
    <p>at Microsoft.AspNet.Builder.UseMiddlewareExtensions.&lt;>c__DisplayClass2_0.b__0(RequestDelegate next)</p>
    
    <p>at Microsoft.AspNet.Builder.Internal.ApplicationBuilder.Build()</p>
    
    <p>at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication()</p>
    
    <p>fail: Microsoft.AspNet.Hosting.Internal.HostingEngine[7]</p>
  </blockquote>
  
  <p>I'm sure that the Constructor signature I use is wrong in some way but I'm not able to find a suitable documentation for this, since it seems like there are dozens of deprecated ones.</p>
  
  <p>This is the AuthenticationMiddleware:</p>
  
  <pre><code>public class BasicAuthenticationMiddleware : AuthenticationMiddleware&lt;BasicAuthOptions&gt;
  {
      public BasicAuthenticationMiddleware(
          RequestDelegate next, 
          BasicAuthOptions options, 
          ILoggerFactory loggerFactory, 
          IUrlEncoder urlEncoder)
          : base(next, options, loggerFactory, urlEncoder) {}
  
      protected override AuthenticationHandler&lt;BasicAuthOptions&gt; CreateHandler()
      {
          return new BasicAuthenticationHandler();
      }
  }
  </code></pre>
  
  <p>BasicAuthOptions:</p>
  
  <pre><code>public class BasicAuthOptions : AuthenticationOptions {
      public const string Scheme = "BasicAuth";
      public BasicAuthOptions()
      {
          AuthenticationScheme = Scheme;
          AutomaticAuthenticate = true;
      }
  }
  </code></pre>
  
  <p>BasicAuthenticationExtensions</p>
  
  <pre><code>public static class BasicAuthenticationExtensions
  {
      public static void UseBasicAuthentication(this IApplicationBuilder builder) {
          builder.UseMiddleware&lt;BasicAuthenticationMiddleware&gt;(new ConfigureOptions&lt;BasicAuthOptions&gt;(o =&gt; new BasicAuthOptions()));
      }
  }
  </code></pre>
  
  <p>Startup.cs:</p>
  
  <pre><code>public class Startup
  {
      public Startup(IHostingEnvironment env)
      {
          // Set up configuration sources.
          var builder = new ConfigurationBuilder()
              .AddJsonFile("appsettings.json")
              .AddEnvironmentVariables();
          Configuration = builder.Build();
      }
  
      public IConfigurationRoot Configuration { get; set; }
  
      // This method gets called by the runtime. Use this method to add services to the container.
      public void ConfigureServices(IServiceCollection services)
      {
          // Add framework services.
          services.AddMvc();
  
          services.AddAuthorization(options =&gt; {
              options.AddPolicy(BasicAuthOptions.Scheme, policy =&gt; policy.Requirements.Add(new BasicAuthRequirement()));
          });
      }
  
      // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
      public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
          loggerFactory.AddConsole(Configuration.GetSection("Logging"));
          loggerFactory.AddDebug();
  
          app.UseIISPlatformHandler();
  
          app.UseStaticFiles();
  
          app.UseBasicAuthentication();
  
          app.UseMvc();
      }
  
      // Entry point for the application.
      public static void Main(string[] args) =&gt; Microsoft.AspNet.Hosting.WebApplication.Run&lt;Startup&gt;(args);
  }
  </code></pre>