Search code examples
c#asp.net-coredbcontextef-database-firstef-core-3.1

Getting Error Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute'


I have a .NET CORE console app which I already created a database for and want to scaffold the model and db context using the Database First Approach , I have a database populated with countries that I want to create a country model for and manipulate in my project.

Important note that I only have one project in this solution

When I type this in my package manager console

Scaffold-DbContext "Data Source=DESKTOP-BJPQ694\\SQLEXPRESS;Initial Catalog=CountryOrigin;User ID=quinoa;Password=chelseatext;ConnectTimeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" Microsoft.EntityFrameworkCore.SqlServer

I get the error :

Could not load type 'Microsoft.EntityFrameworkCore.Infrastructure.DesignTimeProviderServicesAttribute' from assembly 'Microsoft.EntityFrameworkCore, Version=3.1.3.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'

Solution

  • It seems that you might be using older version of Microsoft.EntityFrameworkCore.SqlServer? Try updating it to Microsoft.EntityFrameworkCore.SqlServer 3.1.

    Reason for your error could be DesignTimeProviderServicesAttribute was only supported till Entity Framework Core 1.1 which was under Microsoft.EntityFrameworkCore.Infrastructure.

    As you are using newer versions Microsoft.EntityFrameworkCore.Infrastructure does not include DesignTimeProviderServicesAttribute & throws the error. Verify same on MSDN here