Efcore.pg: Scaffold-DbContext - Unable to find design-time provider assembly.

Created on 1 Jun 2017  路  18Comments  路  Source: npgsql/efcore.pg

I've created .NET Framework 4.6.1 Console project in VS 2015.
I try to use EntityFrameworkCore with Npgsql.EntityFrameworkCore.PostgreSQL driver.

I have the following packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.AspNetCore.Hosting.Abstractions" version="1.1.1" targetFramework="net461" />
  <package id="Microsoft.AspNetCore.Hosting.Server.Abstractions" version="1.1.1" targetFramework="net461" />
  <package id="Microsoft.AspNetCore.Http.Abstractions" version="1.1.1" targetFramework="net461" />
  <package id="Microsoft.AspNetCore.Http.Features" version="1.1.1" targetFramework="net461" />
  <package id="Microsoft.CSharp" version="4.3.0" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.Design" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.Relational" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.Relational.Design" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.EntityFrameworkCore.Tools" version="2.0.0-preview1-final" targetFramework="net461" developmentDependency="true" />
  <package id="Microsoft.Extensions.Caching.Abstractions" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.Caching.Memory" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.Configuration" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.Configuration.Abstractions" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.DependencyInjection" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.FileProviders.Abstractions" version="1.1.0" targetFramework="net461" />
  <package id="Microsoft.Extensions.Logging" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.Logging.Abstractions" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.Options" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.Extensions.Primitives" version="2.0.0-preview1-final" targetFramework="net461" />
  <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net461" />
  <package id="Microsoft.Packaging.Tools" version="1.0.0-preview1-25301-01" targetFramework="net461" />
  <package id="NETStandard.Library" version="2.0.0-preview1-25301-01" targetFramework="net461" />
  <package id="Npgsql" version="3.2.2" targetFramework="net461" />
  <package id="Npgsql.EntityFrameworkCore.PostgreSQL" version="2.0.0-preview1" targetFramework="net461" />
  <package id="Npgsql.EntityFrameworkCore.PostgreSQL.Design" version="2.0.0-preview1" targetFramework="net461" />
  <package id="Remotion.Linq" version="2.1.1" targetFramework="net461" />
  <package id="System.Collections" version="4.0.11" targetFramework="net461" />
  <package id="System.Collections.Immutable" version="1.3.1" targetFramework="net461" />
  <package id="System.ComponentModel" version="4.3.0" targetFramework="net461" />
  <package id="System.ComponentModel.Annotations" version="4.3.0" targetFramework="net461" />
  <package id="System.Data.Common" version="4.3.0" targetFramework="net461" />
  <package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net461" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.3.0" targetFramework="net461" />
  <package id="System.Interactive.Async" version="3.1.1" targetFramework="net461" />
  <package id="System.Linq" version="4.1.0" targetFramework="net461" />
  <package id="System.Linq.Expressions" version="4.1.0" targetFramework="net461" />
  <package id="System.Linq.Queryable" version="4.0.1" targetFramework="net461" />
  <package id="System.ObjectModel" version="4.0.12" targetFramework="net461" />
  <package id="System.Reflection" version="4.1.0" targetFramework="net461" />
  <package id="System.Reflection.Extensions" version="4.0.1" targetFramework="net461" />
  <package id="System.Runtime" version="4.1.0" targetFramework="net461" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.4.0-preview1-25305-02" targetFramework="net461" />
  <package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net461" />
  <package id="System.Text.Encodings.Web" version="4.3.0" targetFramework="net461" />
  <package id="System.Threading" version="4.0.11" targetFramework="net461" />
  <package id="System.Threading.Tasks.Extensions" version="4.3.0" targetFramework="net461" />
  <package id="System.ValueTuple" version="4.3.0" targetFramework="net461" />
</packages>`

When I try to execute the following command in Package Manager Console:
Scaffold-DbContext "Host=localhost;Database=mydatabase;Username=myuser;Password=mypassword" Npgsql.EntityFrameworkCore.PostgreSQL

I get the following error:
Unable to find design-time provider assembly. Please install the Npgsql.EntityFrameworkCore.PostgreSQL.Design NuGet package and ensure that the package is referenced by the project.

I've checked the bin\Debug directory of project and I see there both files:
Npgsql.EntityFrameworkCore.PostgreSQL.dll and
Npgsql.EntityFrameworkCore.PostgreSQL.Design.dll

All 18 comments

Please post your csproj, that's the really relevant bit.

Also, since you posted a packages.config, I just realized you're still using the old csproj-style project. I'm really not sure that's supposed to work - try migrating to the new csproj (which contains <PackageReference> nodes).

See attached csproj file.
EF-postgres.zip
I do not understand what is new format. Is it used by VS 2017? For some reasons I cannot use it.

I've added a -Verbose argument to Scaffold-DbContext command and got the following error:
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to find design-time provider assembly. Please install the Npgsql.EntityFrameworkCore.PostgreSQL.Design NuGet package and ensure that the package is referenced by the project. ---> System.IO.FileLoadException: Could not load file or assembly 'Npgsql.EntityFrameworkCore.PostgreSQL.Design, Version=1.2.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
It points to 1.2.0 version of Design assembly but I suppose it should point to 2.0.0.
It looks like it is defined here:
https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/blob/dev/src/EFCore.PG/Properties/AssemblyInfo.cs

Same problem here, with visual studio community 2017.

My example project
EfCoreNpgSql.zip

Command: Scaffold-DbContext "Port=5434;Server=localhost;Database=base_340_dev_suplima;UserId=postgres;Password=1234" Npgsql.EntityFrameworkCore.PostgreSQL -Table cfop,clientes,clientes_telefones,clientesformapagto,configuracoes,empresa,empresa_telefones,formapagto,formapagto_finalizadora,grupos,historico,movimentacoescaixa,municipios,ncm,nfeinfo,operacoes,produtos,saidasnf,tipodocumento,tributoestrutura,tributooperacao,usuarios,versaobase,vcontasareceber -Verbose

Gif with problem reproduce:
npgsql

Any solution at moment?

For everyone trying to use Entity Framework Core 1.2.0 / 2.0.0, note that it's not yet released. Specifically, don't try to use anything except preview1 which was at least an "official" prerelease.

There's a good chance scaffolding is broken in 2.0.0, I know there have been lots of changes. I'll have that fixed for preview2.

Of course, it's recommended to use 1.1 for now, unless there's something you really specifically need in 2.0.0.

Does any one know whether this issue has been fixed or not. Please provide an update

There is some important data missing in this issue - since 2.0.0 there's no longer a separate design package. Can someone please confirm that they're still hitting, and confirm the following:

  • Which EF Core version they're using (both Npgsql package and EF Core).
  • Which .NET version they're using (.NET Framework or Core, and which exact version)
  • As I requested above, please post your full csproj.

Without full details I can't do anything...

I am using Npgsql.EntityFrameworkCore.Postgresql 2.0.1
NpgSQL 3.2.6
I tried with .Net Core and .Net Standard 2.0

I am getting the issue when i try to use the scaffhold command

Scaffold-DbContext "Host=localhost;Database=CoreDB;Username=postgres;Password=postgres" Npgsql.EntityFrameworkCore.PostgreSQL -OutputDir Models -Context "ApplicationDBContext"
Unable to find provider assembly with name Npgsql.EntityFrameworkCore.PostgreSQL. Ensure the specified name is correct and is referenced by the project.

Installed Microsoft.EntityFrameworkCore.Desgin (Latest Stable Version)
NpgSQL.EntityFrameworkCore.PostgreSQL (Latest Stable Version)
NpgSQLEntityFrameworkCore.PostgresQL. Design (Latest Stable Version)

Tried with both .Net STandard 2.0 Class Library and .Net Core 2.0 Class Library
When we try to execute the scaffhold command as mentioned above, it gives the issue

All I am trying to do is to connect to an existing database using entity framework core and executing the scaffhold command to generate the POCO Classes

I get the same issue.
EFCore 2.0.0
.NETCore 2.0
NpgSQL.EntityFrameworkCore.PostgreSQL (Latest Stable Version - 2.0.1)
Npgsql.EntityFrameworkCore.PostgreSQL.Design (preview 2.0.0-preview1, but also tried stable 1.1.1)
Full .csproj:
image

And my full verbose output:
image

How ever if we try the Code First Approach we are not facing any issue.
Has any one tried creating using .net core cli to generate the poco classes
dotnet ef -

Has any one tried creating using .net core cli to generate the poco classes
dotnet ef -"

I was able to get this working using the dotnet cli command instead of the PowerShell command using this template: dotnet ef dbcontext scaffold "Host=localhost;Database=mydatabase;Username=myuser;Password=mypassword" Npgsql.EntityFrameworkCore.PostgreSQL

Closing, this should no longer be relevant as design has been merged into the main EF Core assembly.

Was this page helpful?
0 / 5 - 0 ratings