8

I am using ASP.NET Core 1.1 and I have the following on startup:

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddUserSecrets();

I am using csproj file instead of JSON where I added:

<PropertyGroup>
   <UserSecretsId>8844d677-223b-4527-a648-387a65933d55</UserSecretsId>
</PropertyGroup>

But when I run the command:

dotnet ef migrations add "InitialCommit"

I get the error:

An error occurred while calling method 'ConfigureServices' on startup class 'Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Could not find 'UserSecretsIdAttribute' on assembly 'ef, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"

Any idea why?

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481

3 Answers3

7

You have run into this issue: https://github.com/aspnet/Configuration/issues/543

The solution is to change your call .AddUserSecrets() to .AddUserSecrets(Assembly assembly)

See this announcement about how deprecating project.json required a breaking change to user secrets: https://github.com/aspnet/Announcements/issues/209

natemcmaster
  • 25,673
  • 6
  • 78
  • 100
  • 1
    If you get the error `'ConfigurationBuilder' does not contain a definition for 'AddUserSecrets'`, make sure you add this missing Nuget package: `Microsoft.Extensions.Configuration.UserSecrets`. – Lauren Rutledge Mar 26 '19 at 21:31
1

I had this issue also. My solution was to install the nuget package Microsoft.Extensions.Configuration.UserSecrets.

AskYous
  • 4,332
  • 9
  • 46
  • 82
0

It finally worked for me when I changed a version of package in .csproj:

<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />

to:

<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
Łukasz Stempek
  • 421
  • 6
  • 8