If you are starting your project with ASP.NET Core Web Application, most probably you will not encounter the errors below. Add-Migration command will work without any problems. I started my project with class libraries for my Domain and Data layer and I didn’t know that adding migration needs a lot of ceremonies.
I’m starting to play around with Entity Framework Core and I am so excited about it. When I get to the part where I have to add a migration, I typed in the command
Where init is the migration name. Then, this happened
Could not load file or assembly ‘System.Collections.Immutable, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’. The located assembly’s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
It took me almost an hour to find a solution for this. But the solution is very simple. Just add another project like a console app and make it as your StartUp Project
Everything should work right? Not yet. If you run add-migration again, you will receive this error
Could not load file or assembly ‘Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null’. The system cannot find the file specified.
The error is straightforward, you just have to go to Nuget Package Manager and install the Microsoft.EntityFrameworkCore.Design in your Sandbox/Console App.
Run the add-migration again and everything should work fine.