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

EF Core tools does not work in combination with Azure KeyVault #26665

Closed
zyofeng opened this issue Nov 13, 2021 · 11 comments
Closed

EF Core tools does not work in combination with Azure KeyVault #26665

zyofeng opened this issue Nov 13, 2021 · 11 comments

Comments

@zyofeng
Copy link

zyofeng commented Nov 13, 2021

If I add AzureKeyVault using the standard Azure.Extensions.AspNetCore.Configuration.Secrets library as below
builder.Configuration.AddAzureKeyVault(new Uri("VaultUri"), new DefaultAzureCredential());

add-migration will fail to generate any migration code
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Value cannot be null. (Parameter 'uriString')

Commenting out the AddAzureKeyVault line and everything works.

Repo replicating the issue
https://github.com/zyofeng/keyvault-ef-migration

@zyofeng zyofeng changed the title EF Core add-migration does not work in combination with Azure KeyVault EF Core tools does not work in combination with Azure KeyVault Nov 13, 2021
@ErikEJ
Copy link
Contributor

ErikEJ commented Nov 13, 2021

Where is the value of "ValutUri" set?

@zyofeng
Copy link
Author

zyofeng commented Nov 13, 2021

I have removed the actual keyvault URI as well as the db connection string (as it was tied to my work azure acc) you can hardcode it in the format of https://.vault.azure.net/ and you can use any azure keyvault and whatever is stored there isn't important.

@ajcvickers
Copy link
Contributor

@zyofeng What is the actual code for this line?

builder.Configuration.AddAzureKeyVault(new Uri("VaultUri"), new DefaultAzureCredential());

Obviously, this is going to fail. But I assume you actually have some code that reads the URI from somewhere. Presumably, the configuration? What does that code look like?

Also, what is the actual exception message and stack trace? (You can get this by running the dotnet ef command with --verbose.

@zyofeng
Copy link
Author

zyofeng commented Nov 18, 2021

For this example Im hardcoding it, you can replace it with your own uri.
builder.Configuration.AddAzureKeyVault(new Uri("https://ef-core-migration.vault.azure.net/"), new DefaultAzureCredential());

Here is the error Im getting

add-migration Init -verbose
Using project 'NZFM.Common.Web'.
Using startup project 'NZFM.Common.Web'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.deps.json --additionalprobingpath C:\Users\zyofe.nuget\packages --runtimeconfig C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.runtimeconfig.json C:\Users\zyofe.nuget\packages\microsoft.entityframeworkcore.tools\6.0.0\tools\netcoreapp2.0\any\ef.dll migrations add Init --json --verbose --no-color --prefix-output --assembly C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.dll --project C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj --startup-assembly C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.dll --startup-project C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj --project-dir C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\ --language C# --configuration Debug --working-dir C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration --root-namespace NZFM.Common.Web --nullable
Using assembly 'NZFM.Common.Web'.
Using startup assembly 'NZFM.Common.Web'.
Using application base 'C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0'.
Using working directory 'C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration'.
Using root namespace 'NZFM.Common.Web'.
Using project directory 'C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'NZFM.Common.Web'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
System.InvalidOperationException: Unable to build IHost
at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.CreateHost()
at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass8_0.b__0(String[] args)
at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass11_0.b__3(String[] args)
at Microsoft.EntityFrameworkCore.Design.Internal.AppServiceProviderFactory.CreateFromHosting(String[] args)
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Unable to build IHost
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'TestDbContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'TestDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions1[NZFM.Common.Web.TestDbContext]' while attempting to activate 'NZFM.Common.Web.TestDbContext'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.<FindContextTypes>b__13() --- End of inner exception stack trace --- at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.<FindContextTypes>b__13() at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to create an object of type 'TestDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

@zyofeng
Copy link
Author

zyofeng commented Nov 18, 2021

If I comment this line out

//builder.Configuration.AddAzureKeyVault(new Uri("https://ef-core-migration.vault.azure.net/"), new DefaultAzureCredential());

The migrations are generated correctly

Using project 'NZFM.Common.Web'.
Using startup project 'NZFM.Common.Web'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.deps.json --additionalprobingpath C:\Users\zyofe.nuget\packages --runtimeconfig C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.runtimeconfig.json C:\Users\zyofe.nuget\packages\microsoft.entityframeworkcore.tools\6.0.0\tools\netcoreapp2.0\any\ef.dll migrations add Init --json --verbose --no-color --prefix-output --assembly C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.dll --project C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj --startup-assembly C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.dll --startup-project C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj --project-dir C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\ --language C# --configuration Debug --working-dir C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration --root-namespace NZFM.Common.Web --nullable
Using assembly 'NZFM.Common.Web'.
Using startup assembly 'NZFM.Common.Web'.
Using application base 'C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0'.
Using working directory 'C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration'.
Using root namespace 'NZFM.Common.Web'.
Using project directory 'C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'NZFM.Common.Web'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
Using application service provider from Microsoft.Extensions.Hosting.
Found DbContext 'TestDbContext'.
Finding DbContext classes in the project...
Using context 'TestDbContext'.
Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 6.0.0 initialized 'TestDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer:6.0.0' with options: None
Finding design-time services referenced by assembly 'NZFM.Common.Web'...
Finding design-time services referenced by assembly 'NZFM.Common.Web'...
No referenced design-time services were found.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'NZFM.Common.Web'...
No design-time services were found.
Writing migration to 'C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\Migrations\20211118171342_Init.cs'.
Writing model snapshot to 'C:\Users\zyofe\Source\Repos\zyofeng\keyvault-ef-migration\Migrations\TestDbContextModelSnapshot.cs'.
To undo this action, use Remove-Migration.

@zyofeng
Copy link
Author

zyofeng commented Nov 18, 2021

No difference using dotnet ef migrations

PM> dotnet ef migrations add Init --verbose
Using project 'C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj'.
Using startup project 'C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj'.
Writing 'C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\obj\NZFM.Common.Web.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\zyofe\AppData\Local\Temp\tmp36EE.tmp /verbosity:quiet /nologo C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj
Writing 'C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\obj\NZFM.Common.Web.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\zyofe\AppData\Local\Temp\tmp3895.tmp /verbosity:quiet /nologo C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj
Build started...
dotnet build C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj /verbosity:quiet /nologo
C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\TestDbContext.cs(15,23): warning CS8618: Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj]

Build succeeded.

C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\TestDbContext.cs(15,23): warning CS8618: Non-nullable property 'Description' must contain a non-null value when exiting constructor. Consider declaring the property as nullable. [C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj]
1 Warning(s)
0 Error(s)

Time Elapsed 00:00:01.07
Build succeeded.
dotnet exec --depsfile C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.deps.json --additionalprobingpath C:\Users\zyofe.nuget\packages --runtimeconfig C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.runtimeconfig.json C:\Users\zyofe.dotnet\tools.store\dotnet-ef\6.0.0\dotnet-ef\6.0.0\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations add Init --assembly C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.dll --project C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj --startup-assembly C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0\NZFM.Common.Web.dll --startup-project C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\NZFM.Common.Web.csproj --project-dir C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\ --root-namespace NZFM.Common.Web --language C# --framework net6.0 --nullable --working-dir C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration --verbose
Using assembly 'NZFM.Common.Web'.
Using startup assembly 'NZFM.Common.Web'.
Using application base 'C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration\bin\Debug\net6.0'.
Using working directory 'C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration'.
Using root namespace 'NZFM.Common.Web'.
Using project directory 'C:\Users\zyofe\source\repos\zyofeng\keyvault-ef-migration'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'NZFM.Common.Web'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
System.InvalidOperationException: Unable to build IHost
at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.CreateHost()
at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass8_0.b__0(String[] args)
at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass11_0.b__3(String[] args)
at Microsoft.EntityFrameworkCore.Design.Internal.AppServiceProviderFactory.CreateFromHosting(String[] args)
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Unable to build IHost
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'TestDbContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'TestDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions1[NZFM.Common.Web.TestDbContext]' while attempting to activate 'NZFM.Common.Web.TestDbContext'. at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters) at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.<FindContextTypes>b__13() --- End of inner exception stack trace --- at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.<FindContextTypes>b__13() at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to create an object of type 'TestDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

@ajcvickers
Copy link
Contributor

@zyofeng This looks like a timeout issue, which is fixed in 6.0.1 by dotnet/runtime#60891

@ghorsey
Copy link

ghorsey commented Nov 23, 2021

I am on version 6.0.1 using azure keyvault and azure appconfiguration to manage my secrets and I am still getting this issue:

$ dotnet ef migrations add UpdateLogEntriesObject -s ..\..\Tmtrcs.Web\ -o .\Data\Migrations\ --verbose
Using project 'D:\code\teametrics\Tmtrcs\src\app\Tmtrcs.Repository.SqlServer\Tmtrcs.Repository.SqlServer.csproj'.
Using startup project 'D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\Tmtrcs.Web.csproj'.
Writing 'D:\code\teametrics\Tmtrcs\src\app\Tmtrcs.Repository.SqlServer\obj\Tmtrcs.Repository.SqlServer.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\geoff\AppData\Local\Temp\tmpF346.tmp /verbosity:quiet /nologo D:\code\teametrics\Tmtrcs\src\app\Tmtrcs.Repository.SqlServer\Tmtrcs.Repository.SqlServer.csproj
Writing 'D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\obj\Tmtrcs.Web.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\geoff\AppData\Local\Temp\tmpF55A.tmp /verbosity:quiet /nologo D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\Tmtrcs.Web.csproj
Build started...
dotnet build D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\Tmtrcs.Web.csproj /verbosity:quiet /nologo

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:07.07
Build succeeded.
dotnet exec --depsfile D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\bin\Debug\net6.0\Tmtrcs.Web.deps.json --additionalprobingpath C:\Users\geoff\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\bin\Debug\net6.0\Tmtrcs.Web.runtimeconfig.json C:\Users\geoff\.nuget\packages\dotnet-ef\6.0.0\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations add UpdateLogEntriesObject -o .\Data\Migrations\ --assembly D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\bin\Debug\net6.0\Tmtrcs.Repository.SqlServer.dll --project D:\code\teametrics\Tmtrcs\src\app\Tmtrcs.Repository.SqlServer\Tmtrcs.Repository.SqlServer.csproj --startup-assembly D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\bin\Debug\net6.0\Tmtrcs.Web.dll --startup-project D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\Tmtrcs.Web.csproj --project-dir D:\code\teametrics\Tmtrcs\src\app\Tmtrcs.Repository.SqlServer\ --root-namespace Tmtrcs.Repository.SqlServer --language C# --framework net6.0 --working-dir D:\code\teametrics\Tmtrcs\src\app\Tmtrcs.Repository.SqlServer --verbose
Using assembly 'Tmtrcs.Repository.SqlServer'.
Using startup assembly 'Tmtrcs.Web'.
Using application base 'D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web\bin\Debug\net6.0'.
Using working directory 'D:\code\teametrics\Tmtrcs\src\Tmtrcs.Web'.
Using root namespace 'Tmtrcs.Repository.SqlServer'.
Using project directory 'D:\code\teametrics\Tmtrcs\src\app\Tmtrcs.Repository.SqlServer\'.
Remaining arguments: .
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider in assembly 'Tmtrcs.Web'...
Finding Microsoft.Extensions.Hosting service provider...
Using environment 'Development'.
System.InvalidOperationException: Unable to build IHost
   at Microsoft.Extensions.Hosting.HostFactoryResolver.HostingListener.CreateHost()
   at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass8_0.<ResolveHostFactory>b__0(String[] args)
   at Microsoft.Extensions.Hosting.HostFactoryResolver.<>c__DisplayClass11_0.<ResolveServiceProviderFactory>b__3(String[] args)
   at Microsoft.EntityFrameworkCore.Design.Internal.AppServiceProviderFactory.CreateFromHosting(String[] args)
An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Unable to build IHost
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'TmtrcsDbContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'TmtrcsDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
 ---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Tmtrcs.Repository.SqlServer.Data.TmtrcsDbContext]' while attempting to activate 'Tmtrcs.Repository.SqlServer.Data.TmtrcsDbContext'.
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
   at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.<FindContextTypes>b__13()
   --- End of inner exception stack trace ---
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass21_4.<FindContextTypes>b__13()
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
   at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to create an object of type 'TmtrcsDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

Is there a way to extend the timeout, or it that update coming out with a >6.0.1 release?

@ajcvickers
Copy link
Contributor

@ghorsey How/from where did you get 6.0.1?

@ghorsey
Copy link

ghorsey commented Nov 24, 2021

I am sometimes thick when coding too late into the evening.

I was thinking dotnet-ef 6.0.1 came with dotnet SDK 6.0.100

After a full nights sleep, I realize my mistake :)

@Liebeck
Copy link

Liebeck commented Jul 28, 2022

In case someone is running into a similiar error when trying to use Entity Framework Core with Migrations + connection string in a Key vault, where the value of the value is stored in an environment variable. It seems that when running from the package manager console to create migrations, the environment variable is not set.

Based on https://stackoverflow.com/a/54289077/225808,
we can run

$env:CENTRAL_APPLICATION_SETTINGS="your value"
before trying to apply the migration

@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

5 participants