Enable-Migrations Exception calling "SetData" with "2" argument(s)

Other answers suggest this is an issue with your startup project.

As your project is a library, you could try setting your unit test project as your startup project per this answer.

You could also try setting the default project in Package Manager Console to your library project per the accepted answer here.

You might run into issues with where the migrations are created. If you need further control, in EF6 there are various arguments you can use with Enable-Migrations as detailed in this answer but I don't have enough knowledge in this area to guide you further. You might need to do some reading.


2018 update - if the accepted answer doesn't help, see this github issue on the EF6 repository. Apparently code migration commands don't work with the new project format. In order for the migrations commands to work, you need to create a Class Library (.NET Framework) project (old standard), move all the files there, add all the needed dependencies and run the command.

EDIT: I just ran into this problem by creating a Class Library (.NET Standard) project on VisualStudio 2017 15.6.6 using EntityFramework 6.2.0. Creating an "old standard" project as explained above fixes it.


To be free from defining startup project explicitly , you can use the command:

Enable-Migrations -EnableAutomaticMigrations -ProjectName Components -StartupProjectName Components

The parameters are:

-ProjectName

Specifies the project that the scaffolded migrations configuration class will be added to (configuration.cs). If omitted, the default project selected in package manager console is used.

-StartUpProjectName

Specifies the configuration file to use for named connection strings. If omitted, the specified project's configuration file is used.

To get more details for the command, run:

get-help enable-migrations -Full