Efcore: Update database issue

Created on 28 Nov 2016  路  3Comments  路  Source: dotnet/efcore

Steps to reproduce

  1. add migration (successful)
  2. update database (not successful)

The issue

Hey guys, i'm trying to make the code first migrations on an ASP .NET Core project (1.1.0) with Entity Framework Core (1.1.0) and whenever I try to load my database with the update database command it log me the following error:

Exception message:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at Microsoft.EntityFrameworkCore.Storage.Internal.SqlServerConnection.CreateDbConnection()
at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Could not load file or assembly 'System.Data.SqlClient, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

Further technical details

I tried to install the System.Data.SqlClient v4.1.0 but it gave me dependency issues.
Any solutions? Here is my project.json:
{
"ConnectionStrings": {
"db": "Server=.\;Database=dbname;Trusted_Connection=True;"
},
"dependencies": {
"LinqKit.Microsoft.EntityFrameworkCore": "1.1.9",
"Microsoft.AspNetCore": "1.1.0",
"Microsoft.AspNetCore.Identity": "1.1.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Relational": "1.1.0",
"Microsoft.EntityFrameworkCore.Relational.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"NETStandard.Library": "1.6.1",
"System.Data.SqlClient": "4.3.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"runtimes": {
"win10-x64": {}
},
"version": "1.0.0-*",
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
"Microsoft.DotNet.Watcher.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
}
}

EF Core version: 1.1.0
Operating system: Windows 10 x64
Visual Studio version: 2015 Community Update 3
The project is a class library in .NET Core.

Most helpful comment

#7068 solved my problem, I'm not sure why so if somebody can explain why this project.json fixed the problem I would thank him/her all my life:

{
"ConnectionStrings": {
"db": "Server=.\;Database=dbname;Trusted_Connection=True;"
},
"dependencies": {
"LinqKit.Microsoft.EntityFrameworkCore": "1.1.9",
"Microsoft.AspNetCore": "1.1.0",
"Microsoft.AspNetCore.Identity": "1.1.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Relational": "1.1.0",
"Microsoft.EntityFrameworkCore.Relational.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"NETStandard.Library": "1.6.1",
"System.Data.SqlClient": "4.3.0",
"System.Runtime": "4.3.0",
"System.Data.Common": "4.3.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
},
"netcoreapp1.0": {
"imports": [
"portable-net40+sl5+win8+wp8+wpa81",
"portable-net45+win8+wp8+wpa81"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0-"
}
}
}
},
"runtimes": {
"win10-x64": {}
},
"version": "1.0.0-
",
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
"Microsoft.DotNet.Watcher.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
}
}

All 3 comments

#7068 solved my problem, I'm not sure why so if somebody can explain why this project.json fixed the problem I would thank him/her all my life:

{
"ConnectionStrings": {
"db": "Server=.\;Database=dbname;Trusted_Connection=True;"
},
"dependencies": {
"LinqKit.Microsoft.EntityFrameworkCore": "1.1.9",
"Microsoft.AspNetCore": "1.1.0",
"Microsoft.AspNetCore.Identity": "1.1.0",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Relational": "1.1.0",
"Microsoft.EntityFrameworkCore.Relational.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"NETStandard.Library": "1.6.1",
"System.Data.SqlClient": "4.3.0",
"System.Runtime": "4.3.0",
"System.Data.Common": "4.3.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
},
"netcoreapp1.0": {
"imports": [
"portable-net40+sl5+win8+wp8+wpa81",
"portable-net45+win8+wp8+wpa81"
],
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.1.0-"
}
}
}
},
"runtimes": {
"win10-x64": {}
},
"version": "1.0.0-
",
"tools": {
"Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
"Microsoft.DotNet.Watcher.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Design": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
}
}

Had you executed Update-Database command from executable project?
Suggestion for anyone seeking solutions to similar problem is to run the command from an executable project even if your EF core is in library project.
Running update-database migrations command from library project gives that error.

The following project.json will create a standalone .NET Standard library. The dotnet ef command doesn't work on standalone projects and has many limitaitons on .NET Standard libraries.

{
  "frameworks": {
    "netstandard1.6": {
      "dependencies": {
        "NETStandard.Library": "1.6.1"
      }
    }
  },
  "runtimes": {
    "win10-x64": {}
  }
}

Whereas this project.json will create a portable, .NET Core application. This is supported by dotnet ef.

{
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.1.0"
        }
      }
    }
  }
}
Was this page helpful?
0 / 5 - 0 ratings