Ehsan Hafeez
Ehsan Hafeez

Reputation: 658

Entity framework core 1.1.2 migration exception

I am getting following strange exceptions.

I already saw following thread discussing about downgrading Microsoft.EntityFrameworkCore.Tools to 1.1.1 which I already did, but still these exceptions are appearing.

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)

Can any body help in this regard.

Upvotes: 2

Views: 790

Answers (2)

Colm
Colm

Reputation: 155

Just to note in retrospect that I got this error while trying to run a dotnet CLI command. The problem I found was that the CLI environment was defaulting to use the .NET Core 2.0 version of the dotnet and ef commands but I needed to use the .NET Core 1.1 version because that was what the package versions were built against.

I discovered (by running dotnet --info) that there was more than one version of .NET Core SDK installed on the environment and the Path pointed to the latest by default. To use the older version I added a global.json file in the solution root with the specific version number. e.g.

{
  "sdk": {
    "version": "1.1.11"
  }
}

and everything worked.

Upvotes: 2

bricelam
bricelam

Reputation: 30375

Make sure all your versions align.

<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.5" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.5" />
</ItemGroup>

<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
                          Version="1.1.5" />
</ItemGroup>

Upvotes: 0

Related Questions