Could not load file or assembly netstandard when I add migration

0

I have an ASP.Net Core 3.0 solution with 2 projects: Web (start project) and Core (class library). I try to create a migration using Package Manager Console:

add-migration Initial -Project Core -StartupProject Web

and get the following error:

Could not load file or assembly 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Both projects have Microsoft.EntityFrameworkCore.SqlServer and Microsoft.EntityFrameworkCore.Tools in references. That's how I create a connection in Startup.cs:

public void ConfigureServices(IServiceCollection services)
{
    var connection = Configuration.GetConnectionString("DefaultConnection");
    services.AddDbContext<ApplicationContext>(options =>
    options.UseSqlServer(connection));
    services.AddControllersWithViews();
}

and my connectionstring in appsettings.json:

"ConnectionStrings": {
        "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=FinApp;Trusted_Connection=True;"
    }

Here's my ApplicationContext.cs:

public class ApplicationContext : DbContext
{
    public DbSet<Account> Accounts { get; set; }
    public DbSet<Category> Categories { get; set; }
    public DbSet<Currency> Currencies { get; set; }
    public DbSet<Operation> Operations { get; set; }
    public DbSet<User> Users { get; set; }

    public ApplicationContext()
    {
    }
}

Does anyone have the same issue?

c#
asp.net-core
ef-migrations
.net-standard
asked on Stack Overflow Feb 22, 2020 by Avitale

1 Answer

0

I think you must define the Context contractor like this:

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
answered on Stack Overflow Feb 23, 2020 by alirezasejdei • edited Feb 23, 2020 by nnnmmm

User contributions licensed under CC BY-SA 3.0