Failed to initialize CoreCLR, HRESULT: 0x80004005 when doing a dotnet ef migrations

The Problem

Last week I was creating a new DbContext library and every time I tried to do a migration I kept getting a strange error   Failed to initialize CoreCLR, HRESULT: 0x80004005

> dotnet ef migrations add init
Build started...
Build succeeded.
Failed to initialize CoreCLR, HRESULT: 0x80004005

The Process

I've created DbContexts classes and projects countless times, and I just couldn't figure out what was going wrong.  I loaded up some older projects and tested migration commands without any issues.  I compared the code and everything looked fine to me.

This was driving me nuts and after scouring the web, I still couldn't find the answer. 

Finally, after comparing the other projects what felt like a thousand times, it dawned on me!  It was a stupid mistake but unfortunately wasted an entire day trying to figure it out, so I'm posting the information here in case anyone else runs into the same issue... and as a quick reminder to me in case, it happens to me again in the future.

Resolution / Realization

I totally forgot to add the Nuget package of Microsoft.EntityFrameworkCore.Tools, the .Tools package is what allows you to issue migration commands against your libraries. 

Since I don't create new DbContext projects all the time, it was a simple oversight on my part but very hard to diagnose based on the error message from the command line.

So in my case, the following NuGet packages were required:

  • Microsoft.EntityFrameworkCore <- Standard Library for DbContext, DbSet, etc
  • Microsoft.EntityFrameworkCore.Tools <- required to create and manage migrations
  • Pomelo.EntityFrameworkCore.MySql <- Library for MySql connections

 

 

- Happy Coding

Game Over Image: Photo by Sigmund on Unsplash