Error running update-database entityframeworkcore 2

asp.net-core-2.0 asp.net-core-webapi c# entity-framework-core

Question

I have EntityFrameworkCore 2.0.2 installed in a class library on a solution containing an AspNet Core WebApi.

I have the following packages installed in the project;

Microsoft.AspNetCore.Identity.EntityFrameworkCore - 2.0.2

Microsoft.EntityFrameworkCore - 2.0.2

Microsoft.EntityFrameworkCore.SqlServer - 2.0.2

Microsoft.Extensions.Identity.Stores - 2.0.2

System.Data.SqlClient - 4.4.3

My Class library project invokes the context as follows;

 public class MyContextFactory : IDesignTimeDbContextFactory<MyDataContext>
    {
        public MyContextFactory()
        {
        }

        public MyDataContext CreateDbContext(string[] args)
        {
            var builder = new DbContextOptionsBuilder<MyDataContext>();
            builder.UseSqlServer(DbGlobals.DevDatabase);

            return new MyDataContext(builder.Options);
        }
    }

I am getting the following error, when I try to run the update-database command from the package manager console.

Application startup exception: System.IO.FileNotFoundException: Could not find file 'C:\Users\matt\Source\Repos\project\Services.WebApi\bin\Debug\netcoreapp2.0\ef.xml'.

this now occurs when I try to add-migration as well.

I can't find any detail on ef.xml and how it is generated? Can anyone tell me what is going on here.

If I run an add-migration i get the migration generated, but then get the error;

An error occurred while calling method 'BuildWebHost' on class 'Program'. Continuing without the application service provider. Error: Could not find file 'C:\Users\matt\Source\Repos\project\Services.WebApi\bin\Debug\netcoreapp2.0\ef.xml'.

I have tried cleaning the project, re-compiling (there are no errors), I have also looked in the referenced folder and the file doesn't exist. Nor (from a file search) has it been generated elsewhere?

The migrations have been working fine now?

Per request my BuildwebHost is;

 public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();

and I add EF in my Startup.cs;

        services.AddDbContext<MyDataContext>(
            options => options
            .UseSqlServer(DbGlobals.DevDatabase));
1
1
4/30/2018 12:07:21 PM

Popular Answer

The commands you are using update-database and add-migration don´t look like the supported Entity Framework Core CLI commands:

  • dotnet ef add migrations <migration-name>
  • dotnet ef database update

Also check this SO question for further information: Entity Framework Core 2.0 add-migration not generating anything

0
4/30/2018 11:02:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow