2

I have a .NET Core class library that is the data access layer for multiple web applications. I am using Entity Framework Core 1.1, but I'm having trouble with migrations through PMC. My initial migration worked successfully, but after updating the database and re-launching VS 2017 I get a null exception on the contentRootPath argument when attempting to migrate. I may have made some changes to the project after my successful migration, but I don't remember what they were. This is the error and stack trace:

Both Entity Framework Core and Entity Framework 6 are installed. The Entity Framework Core tools are running. Use 'EntityFramework\Add-Migration' for Entity Framework 6. System.ArgumentNullException: Value cannot be null. Parameter name: contentRootPath at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations..ctor(IOperationReporter reporter, Assembly assembly, Assembly startupAssembly, String environment, String projectDir, String contentRootPath, String rootNamespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<>c__DisplayClass4_0.<.ctor>b__4() at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) 

There is no config file in my migrations directory, and I can't find anything related in the DbContext class. Has anyone else ran into this issue, or know what is causing it?

SqlDbContext class:

using Microsoft.EntityFrameworkCore; using DataLayer.Models.User; namespace DataLayer.Context { public class SqlDbContext : DbContext { public DbSet<User> Users { get; set; } protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseSqlServer(MyDbConfig.SqlConnectionString); } protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<User>() .Ignore(m => m.FullName); base.OnModelCreating(modelBuilder); } } } 
6
  • Are you using both EF6 and EFC? Commented Jun 22, 2017 at 5:53
  • No, I am not using EF6, but it is in the project. Commented Jun 22, 2017 at 19:03
  • I edited your tags... to only show EFC. Can you show us your references? Startup.cs and appsettings.json Commented Jun 22, 2017 at 19:52
  • It's in a Class Library, so there is no Startup.cs or appsettings.json files. I am just storing my connection string in a static class, along with connection strings to other databases that I am accessing. I updated the code snipped with my references. And my mistake before, I meant that EF6 is in the solution, not the project. Commented Jun 23, 2017 at 2:08
  • I just looked at my Nuget packages, and for some reason my EntityFrameworkCore.Tools package was a pre-release version (2.0.0). I just downgraded to 1.1.1, and now migrations are working again. Not sure why it updated to an unstable version, but it's working now. Thanks anyway for you help! Commented Jun 23, 2017 at 2:18

2 Answers 2

1

It turns out that this was due to the Microsoft.EntityFrameworkCore.Tools package being pre-release version 2.0.0, which is not currently a stable version. Downgrading to 1.1.1 fixed the issue.

Sign up to request clarification or add additional context in comments.

2 Comments

Are you sure that you do not mean 1.0.1?
There is no 1.1.1 version though
1

I had this issue in the past and here is the fix:

First, make sure that the version of the SDK you are using is 2.1.200 as you are under Core 1.1 and put this on your global.json:

{ "sdk": { "version": "2.1.200" } } 

Add reference on your .csproj to Microsoft.EntityFrameworkCore.Design and Microsoft.EntityFrameworkCore.Tools.DotNet so you will have:

 <ItemGroup> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.6" PrivateAssets="All" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.1.6" /> </ItemGroup> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.