Add-Migration while using database in separate Docker container throws an error

.net-core entity-framework entity-framework-core


I've created dockerized Core app with auto-generated identity setup (so I've already had by default entity framework configuration). I've created SQL Server as separate container, here is my docker-compose.yml:

version: '3.4'

        image: blazorapp1
            context: .
            dockerfile: Dockerfile
            - db

        image: ""
            ACCEPT_EULA: "Y"

I've tested database configuration: as Visual Studio generated identity setup for me, I could successfully create new users and they were properly stored in memory.

Then I wanted to create new database table:

public class ApplicationDbContext : IdentityDbContext

    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)

    public virtual DbSet<WeightLog> WeightLogs { get; set; }

To apply those changes, I've used Add-Migration WeightLogger in Package Manager Console.

Here is an output:

PM> Add-Migration WeightLogger
Build started...
Build succeeded.
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: C:\root\.nuget\packages\microsoft.aspnetcore.identity.ui\3.1.1\staticwebassets\V4\
Unable to create an object of type 'ApplicationDbContext'. For the different patterns supported at design time, see

There are a couple of things I don't understand here. The first error points me to C:\root\.nuget\packages\microsoft.aspnetcore.identity.ui\3.1.1\staticwebassets\V4\ which does not exist. Then there is the second error telling me that ApplicationDbContext can't be created. Link points me to webpage that tells:

When you create a new ASP.NET Core application, this hook is included by default.

So, does this mean I shouldn't need to configure anything? Why it isn't working then? Should I create migrations differently when using Docker container as environment?

2/15/2020 5:38:16 PM

Popular Answer

I got exactly the same issue and I ended up solving it by deleting the docker-compose project from visual studio and just keep the docker-compose.yaml and manage it through the command line and that solve it.

For those who don't want to remove the docker-compose support for the solution and facing the same issue, I think it is possible to solve it by implementing a design-time interface for the context or using docker ef migrations add command but in all cases, it's an issue that should be reported to Microsoft.

2/23/2020 4:57:00 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow