Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add-Migration ignores IDesignTimeDbContextFactory implementation and starts project instead after upgrading to EFCore 6 #27358

Closed
ghost opened this issue Feb 3, 2022 · 1 comment

Comments

@ghost
Copy link

ghost commented Feb 3, 2022

Hi,

after upgrading to EFCore 6 adding new migration doesn't work as before (and as intended) because adding new migration tries to start the project instead of using IDesignTimeDbContextFactory which results in an infinite loop since our project tries to repeatedly contact several endpoints that are unreachable from development computers. There is only one DbContext in the project and only one IDesignTimeDbContextFactory implementation.

Basically currently we are unable to create new migrations. Everything worked fine on EFCore 2 and EFCore 5 but not anymore on EFCore 6. Could you point us where the problem might be?

IDesignTimeDbContextFactory implementation:

    public class MyDbContextFactory : IDesignTimeDbContextFactory<MyDbContext>
    {
        public MyDbContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<MyDbContext>();

            string resourceName = Routes.PascalCase(Routes.ResourceRoute);

            builder.UseSqlite($"Data Source=/var/opt/cache/{resourceName}.sqlite");

            return new MyDbContext(builder.Options);
        }
    }

Verbose output of adding migration:

EntityFrameworkCore\Add-Migration TestMigration -Verbose
Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework6\Add-Migration' for Entity Framework 6.
Using project 'Inquiry\MyProject'.
Using startup project 'Inquiry\MyProject'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Repos\MyProject\bin\Debug\net6.0\MyProject.deps.json --additionalprobingpath C:\Users\dflorek\.nuget\packages --additionalprobingpath "C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages" --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Repos\MyProject\bin\Debug\net6.0\MyProject.runtimeconfig.json C:\Users\dflorek\.nuget\packages\microsoft.entityframeworkcore.tools\6.0.0\tools\netcoreapp2.0\any\ef.dll migrations add TestMigration --json --verbose --no-color --prefix-output --assembly C:\Repos\MyProject\bin\Debug\net6.0\MyProject.dll --project C:\Repos\MyProject\MyProject.csproj --startup-assembly C:\Repos\MyProject\bin\Debug\net6.0\MyProject.dll --startup-project C:\Repos\MyProject\MyProject.csproj --project-dir C:\Repos\MyProject\ --language C# --configuration Debug --working-dir C:\Repos\ --root-namespace MyProject
Using assembly 'MyProject'.
Using startup assembly 'MyProject'.
Using application base 'C:\Repos\MyProject\bin\Debug\net6.0'.
Using working directory 'C:\Repos\MyProject'.
Using root namespace 'MyProject'.
Using project directory 'C:\Repos\MyProject\'.
Remaining arguments: .
The Entity Framework tools version '6.0.0' is older than that of the runtime '6.0.1'. Update the tools for the latest features and bug fixes. See https://aka.ms/AAc1fbw for more information.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Found IDesignTimeDbContextFactory implementation 'MyDbContextFactory'.
Found DbContext 'MyDbContext'.
Finding application service provider in assembly 'MyProject'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'localhost'.

///OUR APP LOGGING
...

EF Core version: 6.0.1
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .NET 6.0
Operating system: Windows 10
IDE: Visual Studio 2022 v17.0.5

@ghost ghost added the customer-reported label Feb 3, 2022
@ajcvickers
Copy link
Contributor

Duplicate of #27306.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant