title: 'ClaimsIdentity.BootstrapContext' could not be mapped error when initialising database with test data
body: <p>I am trying set up an Authorization server using IdentityServer4. I get the following errors when i try to run a piece of code to generate a test data. below is the code</p>
  
  <pre><code>private static void InitializeDbTestData(IApplicationBuilder app)
      {
          using (var scope = app.ApplicationServices.GetService&lt;IServiceScopeFactory&gt;().CreateScope())
          {
              scope.ServiceProvider.GetRequiredService&lt;PersistedGrantDbContext&gt;().Database.Migrate();
              scope.ServiceProvider.GetRequiredService&lt;ConfigurationDbContext&gt;().Database.Migrate();
              scope.ServiceProvider.GetRequiredService&lt;UserDbContext&gt;().Database.Migrate();
  
              var context = scope.ServiceProvider.GetRequiredService&lt;ConfigurationDbContext&gt;();
  
              if (!context.Clients.Any())
              {
                  foreach (var client in Clients.Get())
                  {
                      context.Clients.Add(client.ToEntity());
                  }
                  context.SaveChanges();
              }
  
              if (!context.Scopes.Any())
              {
                  foreach (var clientSope in Scopes.Get())
                  {
                      context.Scopes.Add(clientSope.ToEntity());
                  }
                  context.SaveChanges();
              }
              var userManager = scope.ServiceProvider.GetRequiredService&lt;UserManager&lt;ApplicationUser&gt;&gt;();
              if (!userManager.Users.Any())
              {
                  foreach (var applicationUser in Users.Get())
                  {
                      foreach (var claim in applicationUser.UserClaims)
                      {
                          //ExtendedClaimsProvider.CreateClaim()
                          applicationUser.Claims.Add(new IdentityUserClaim&lt;Guid&gt;
                          {
                              UserId = applicationUser.Id,
                              ClaimType = claim.Type,
                              ClaimValue = claim.Value,
  
                          });
                      }
  
                      userManager.CreateAsync(applicationUser, "Password123!").Wait();
                  }
              }
          }
      }
  </code></pre>
  
  <p>The error is generated when </p>
  
  <pre><code>scope.ServiceProvider.GetRequiredService&lt;UserDbContext&gt;().Database.Migrate();
  </code></pre>
  
  <p>is executed.</p>
  
  <p>below is the error generated</p>
  
  <pre><code> System.InvalidOperationException was unhandled by user code  HResult=-2146233079  Message=The property 'ClaimsIdentity.BootstrapContext' could not be mapped, because it is of type 'object' which is not a supported primitive type or a valid entity type. Either explicitly map this property, or ignore it.
  </code></pre>
  
  <p>Source=Microsoft.EntityFrameworkCore
    StackTrace:
         at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.PropertyMappingValidationConvention.Apply(InternalModelBuilder modelBuilder)
         at Microsoft.EntityFrameworkCore.Metadata.Conventions.Internal.ConventionDispatcher.OnModelBuilt(InternalModelBuilder modelBuilder)
         at Microsoft.EntityFrameworkCore.Infrastructure.ModelSource.CreateModel(DbContext context, IConventionSetBuilder conventionSetBuilder, IModelValidator validator)
         at System.Collections.Concurrent.ConcurrentDictionary<code>2.GetOrAdd(TKey key, Func</code>2 valueFactory)
         at Microsoft.EntityFrameworkCore.Internal.DbContextServices.CreateModel()
         at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
         at Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)
         at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
         at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
         at Microsoft.EntityFrameworkCore.DbContext.get_Model()
         at Microsoft.EntityFrameworkCore.DbContext.SetTEntity
         at ReportBook.Auth.Startup.InitializeDbTestData(IApplicationBuilder app) in C:\Users\Julius\Documents\Projects\School\Development\ReportBook\ReportBook.Auth\Startup.cs:line 166
         at ReportBook.Auth.Startup.Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) in C:\Users\Julius\Documents\Projects\School\Development\ReportBook\ReportBook.Auth\Startup.cs:line 233
    InnerException: </p>
  
  <p>The following is my startup class</p>
  
  <pre><code>public class Startup
  {
      private readonly IHostingEnvironment _environment;
      public Startup(IHostingEnvironment env)
      {
          var builder = new ConfigurationBuilder()
              .SetBasePath(env.ContentRootPath)
              .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
              .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);
  
          if (env.IsEnvironment("Development"))
          {
              // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
              builder.AddApplicationInsightsSettings(developerMode: true);
          }
          _environment = env;
          builder.AddEnvironmentVariables();
          Configuration = builder.Build();
      }
  
      public IConfigurationRoot Configuration { get; }
  
  
      public void ConfigureServices(IServiceCollection services)
      {
          var connectionString = Configuration["Data:UserAccConnection:ConnectionString"];
          var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
          var cert = new X509Certificate2(Path.Combine(_environment.ContentRootPath, "reportbook.auth.pfx"), "");
          services.AddCors();
  
          // Add framework services.
          services.AddApplicationInsightsTelemetry(Configuration);
  
          services.AddMvc();
          services.AddDbContext&lt;UserDbContext&gt;(options =&gt;
              options.UseSqlServer(connectionString, b =&gt; b.MigrationsAssembly(migrationsAssembly)));
  
          // Register the Identity services.
          services.AddIdentity&lt;ApplicationUser, UserRole&gt;()
              .AddEntityFrameworkStores&lt;UserDbContext, Guid&gt;()
              .AddDefaultTokenProviders();
  
          services.AddIdentityServer()
              .AddOperationalStore(builder =&gt; builder.UseSqlServer(connectionString, options =&gt; options.MigrationsAssembly(migrationsAssembly)))
              .AddConfigurationStore(builder =&gt; builder.UseSqlServer(connectionString, options =&gt; options.MigrationsAssembly(migrationsAssembly)))
              .SetSigningCredential(cert)
              .AddProfileService&lt;IdentityWithAdditionalClaimsProfileService&gt;();
  
          services.AddTransient&lt;IProfileService, IdentityWithAdditionalClaimsProfileService&gt;();
  
          services.AddTransient&lt;IEmailSender, AuthMessageSender&gt;();
          services.AddTransient&lt;ISmsSender, AuthMessageSender&gt;();
  
  
          //services.AddTransient&lt;IDatabaseInitializer, DatabaseInitializer&gt;();
  
       }
      private static void InitializeDbTestData(IApplicationBuilder app)
      {
          using (var scope = app.ApplicationServices.GetService&lt;IServiceScopeFactory&gt;().CreateScope())
          {
              scope.ServiceProvider.GetRequiredService&lt;PersistedGrantDbContext&gt;().Database.Migrate();
              scope.ServiceProvider.GetRequiredService&lt;ConfigurationDbContext&gt;().Database.Migrate();
              scope.ServiceProvider.GetRequiredService&lt;UserDbContext&gt;().Database.Migrate();
  
              var context = scope.ServiceProvider.GetRequiredService&lt;ConfigurationDbContext&gt;();
  
              if (!context.Clients.Any())
              {
                  foreach (var client in Clients.Get())
                  {
                      context.Clients.Add(client.ToEntity());
                  }
                  context.SaveChanges();
              }
  
              if (!context.Scopes.Any())
              {
                  foreach (var clientSope in Scopes.Get())
                  {
                      context.Scopes.Add(clientSope.ToEntity());
                  }
                  context.SaveChanges();
              }
              var userManager = scope.ServiceProvider.GetRequiredService&lt;UserManager&lt;ApplicationUser&gt;&gt;();
              if (!userManager.Users.Any())
              {
                  foreach (var applicationUser in Users.Get())
                  {
                      foreach (var claim in applicationUser.UserClaims)
                      {
                          //ExtendedClaimsProvider.CreateClaim()
                          applicationUser.Claims.Add(new IdentityUserClaim&lt;Guid&gt;
                          {
                              UserId = applicationUser.Id,
                              ClaimType = claim.Type,
                              ClaimValue = claim.Value,
  
                          });
                      }
  
                      userManager.CreateAsync(applicationUser, "Password123!").Wait();
                  }
              }
          }
      }
      // 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.UseApplicationInsightsRequestTelemetry();
  
          app.UseApplicationInsightsExceptionTelemetry();
  
          app.UseDeveloperExceptionPage();
          app.UseStaticFiles();
          app.UseCors(builder =&gt;
              builder.AllowAnyOrigin()
              .AllowAnyHeader()
              .AllowAnyMethod());
  
          app.UseExceptionHandler(
            builder =&gt;
            {
                builder.Run(
                  async context =&gt;
                  {
                      context.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
                      context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
  
                      var error = context.Features.Get&lt;IExceptionHandlerFeature&gt;();
                      if (error != null)
                      {
                          await context.Response.WriteAsync(error.Error.Message).ConfigureAwait(false);
                      }
                  });
            });
  
          app.UseCsp(options =&gt; options.DefaultSources(directive =&gt; directive.Self())
              .ImageSources(directive =&gt; directive.Self()
                 .CustomSources("*"))
              .ScriptSources(directive =&gt; directive.Self()
                  .UnsafeInline())
              .StyleSources(directive =&gt; directive.Self()
                  .UnsafeInline()));
  
          app.UseXContentTypeOptions();
          app.UseXfo(options =&gt; options.Deny());
          app.UseXXssProtection(options =&gt; options.EnabledWithBlockMode());
  
          InitializeDbTestData(app);
          app.UseIdentity();
          app.UseIdentityServer();
  
          app.UseMvcWithDefaultRoute();
          app.UseMvc();
          //databaseInitializer.Seed(app).GetAwaiter().GetResult();
      }
  
  }
  </code></pre>
  
  <p>I will appreciate any help</p>