title: Error defining DbContext of type IdentityDbContext
body: <p>We have an Azure Functions app that uses three databases, one of which is of type "IdentityDbContext".
  Out of the blue, after months of happy use of these contexts, after a rebuild, we run into this error when firing up the Function app:</p>
  
  <blockquote>
    <p>Method Microsoft.Extensions.DependencyInjection.EntityFrameworkServiceCollectionExtensions.AddDbContext: type argument 'xxx.ApplicationDbContext' violates the constraint of type parameter 'TContext'.</p>
  </blockquote>
  
  <p>We've tried to find a change that might cause this, but we are stumped…</p>
  
  <p>Similar questions in Stackoverflow etc suggest it was an issue in earlier versions of Azure Functions, but should be resolved by now.</p>
  
  <p>This is the class for the offending <code>DBcontext</code>:</p>
  
  <pre><code>public class ApplicationDbContext : IdentityDbContext&lt;ApplicationUser&gt;
  {
      public ApplicationDbContext(DbContextOptions&lt;ApplicationDbContext&gt; options)
      : base(options)
      {
          Database.EnsureCreated();
      }
  
      protected override void OnModelCreating(ModelBuilder builder)
      {
          base.OnModelCreating(builder);
          // Customize the ASP.NET Identity model and override the defaults if needed.
          // For example, you can rename the ASP.NET Identity table names and more.
          // Add your customizations after calling base.OnModelCreating(builder);
          builder.Entity&lt;ApplicationUser&gt;().HasMany(e =&gt; e.Claims).WithOne().HasForeignKey(e =&gt; e.UserId).IsRequired().OnDelete(DeleteBehavior.Cascade);
      }
  }
  </code></pre>
  
  <p>And this is where all hell breaks loose:</p>
  
  <pre><code>var services = new ServiceCollection()
      .AddDbContext&lt;MobidotContext&gt;(options =&gt; options.UseSqlServer(config.GetConnectionString("MobidotDbConnection")))
      .AddDbContext&lt;MobilityDbContext&gt;(options =&gt; options.UseSqlServer(config.GetConnectionString("MobilityDbConnection")))
      .AddDbContext&lt;ApplicationDbContext&gt;(options =&gt; options.UseSqlServer(config.GetConnectionString("DefaultConnection")));
  </code></pre>