2

I'm currently busy with an integration of Identity Server 4 using the EntityFramework part of the tutorial on their documentation pages. My project is using .NET Core 2.0.

Everything goes well, up until the point where it tells me to add the migrations using the command line. These commands are:

dotnet ef migrations add InitialIdentityServerPersistedGrantDbMigration -c PersistedGrantDbContext -o Data/Migrations/IdentityServer/PersistedGrantDb
dotnet ef migrations add InitialIdentityServerConfigurationDbMigration -c ConfigurationDbContext -o Data/Migrations/IdentityServer/ConfigurationDb

The first one is executed without issues and adds the migrations to the solution as well. Upon using the second command, it tells me the build failed, with the following errors: 1>Migrations\IdentityServer\PersistedGrantDb\PersistedGrantDbContextModelSnapshot.cs(13,6,13,15): error CS0579: Duplicate 'DbContext' attribute 1>Migrations\IdentityServer\PersistedGrantDb\PersistedGrantDbContextModelSnapshot.cs(16,33,16,43): error CS0111: Type 'PersistedGrantDbContextModelSnapshot' already defines a member called 'BuildModel' with the same parameter types 1>Done building project "IdentityServer.csproj" -- FAILED.

Now, having read some other articles and this announcement, it would seem that the (design-time) DbContext discovery has changed. To remedy this, I changed some of my code. The relevant parts (as far as I know):

Program.cs - extension method:

 public static IWebHost Migrate(this IWebHost webhost)
 {
    using (var scope = webhost.Services.GetService<IServiceScopeFactory>().CreateScope())
    {
        scope.ServiceProvider.GetService<PersistedGrantDbContext>().Database.Migrate();

        using (var dbContext = scope.ServiceProvider.GetRequiredService<ConfigurationDbContext>())
        {
            dbContext.Database.Migrate();
            [etc...]
        }
    }
}

Calling the extension method in Main(...):

var host = BuildWebHost(args).Migrate();
host.Run();

Additionally, I've removed the InitializeDatabase method from Startup.cs.

Having done these things, it pretty much still ends up with the same compilation errors in my solution, after it successfully added the first migration using the command line.

Am I missing something here?

Cheers.

Alain
  • 43
  • 5

1 Answers1

5

In my case, I found I had a PersistedGrantDbContextModelSnapshot.cs* file at both /Data/Migrations and /Migrations. One of these needed to be deleted.

* obviously mine had a different name.

Dan Soper
  • 639
  • 8
  • 18