New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.Internal.DirectConstructorBinding'. Configure your services to use one that can. #11177
Comments
The same problem with EF Core 2.1-preview1-final (but it works with 2.0.1).
Startup:
SqlDbContext:
result of
|
@mexahuk61 I think this link can help you: |
@masoud-bahrami @mexahuk61 Looks like you are using a mixture of EF Core 2.0 packages and EF Core 2.1 preview1 packages. Was your intention to use 2.0 or 2.1 preview1? |
@ajcvickers why do you think I'm using a mixture? Loot at my csprog file: everywhere EF 2.1... |
@mexahuk61 Because |
@ajcvickers oh! You are right! AspNetCore.All package already contains EF. Moreover EF 2.1 depends on DependencyInjection >= 2.1.0 and other important packages... it's strange from my point of view :) Thank you |
@ajcvickers yes you are right! and I think this is very confusing about EF 2 or EF 2.1 |
I update all json packages to use EF 2.0.0 |
It is possible to use EF2.1preview with current stable .net core 2.0? Obviously Package Microsoft.AspNetCore.All 2.1.0-preview1-final is not compatible with netcoreapp2.0 |
@Liero - You can use EF 2.1 preview package with netcoreapp2.0. Instead of referencing Microsoft.AspNetCore.All package add package for EF core provider package you would like to use. |
It worked for me: https://www.youtube.com/watch?v=i_fDTRoMuG0 In terminal: dotnet add package Microsoft.EntityFrameworkCore.Design
|
if you are with net core 2 install the versions of nugget 2.0.X, but if you are with net core 2.1 install versions of nugget 2.1.X |
I came from dotnetcore 2.0.1 and ef 2.0.1 and upgraded to 2.1 for both. Then I got the error when trying to add a migration. After applying @krlosruiz suggestion and installing |
FYI. Adding Microsoft.EntityFrameworkCore.Design to the DB project fixed it for me. |
@mattdone01, greatly appreciate it. Adding it worked for me. |
I´m using MySql, and after installing Microsoft.EntityFrameworkCore.Design in the project, following @krlosruiz, the issue was fixed. |
I's using dotnet core 2 and EF core 2.
I use CLI to generate migration files.
In module which i try to generate Migration file, i use this factory:
`
public class ApplicationDbContextFactory : IDesignTimeDbContextFactory
{
`
And here is project file:
But when i run dotnet ef migrations add initial --verbose, i run into this message
`
dotnet ef migrations add initial --verbose
Using project 'D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\Chakavak.Identity.EntityFrameworkCore.csproj'.
Using startup project 'D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\Chakavak.Identity.EntityFrameworkCore.csproj'.
Writing 'D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\obj\Chakavak.Identity.EntityFrameworkCore.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\masoud\AppData\Local\Temp\tmpB699.tmp /verbosity:quiet /nologo D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\Chakavak.Identity.EntityFrameworkCore.csproj
Writing 'D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\obj\Chakavak.Identity.EntityFrameworkCore.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\masoud\AppData\Local\Temp\tmpB959.tmp /verbosity:quiet /nologo D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\Chakavak.Identity.EntityFrameworkCore.csproj
dotnet build D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\Chakavak.Identity.EntityFrameworkCore.csproj /verbosity:quiet /nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:08.74
dotnet exec --depsfile D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\bin\Debug\netcoreapp2.0\Chakavak.Identity.EntityFrameworkCore.deps.json --additionalprobingpath C:\Users\masoud.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --fx-version 2.0.0 "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools.dotnet\2.0.1\tools\netcoreapp2.0\ef.dll" migrations add initial --assembly D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\bin\Debug\netcoreapp2.0\Chakavak.Identity.EntityFrameworkCore.dll --startup-assembly D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\bin\Debug\netcoreapp2.0\Chakavak.Identity.EntityFrameworkCore.dll --project-dir D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\ --verbose --root-namespace Chakavak.Identity.EntityFrameworkCore
Using assembly 'Chakavak.Identity.EntityFrameworkCore'.
Using startup assembly 'Chakavak.Identity.EntityFrameworkCore'.
Using application base 'D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore\bin\Debug\netcoreapp2.0'.
Using working directory 'D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore'.
Using root namespace 'Chakavak.Identity.EntityFrameworkCore'.
Using project directory 'D:\Chakavak.DotNetCore\Identity\EntityFrameworkCore'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Found IDesignTimeDbContextFactory implementation 'ApplicationDbContextFactory'.
Found DbContext 'ChakavakIdentityDbContext'.
Finding application service provider...
Finding BuildWebHost method...
No entry point was found for assembly 'Chakavak.Identity.EntityFrameworkCore'.
No application service provider was found.
Finding DbContext classes in the project...
Using DbContext factory 'ApplicationDbContextFactory'.
Using context 'ChakavakIdentityDbContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'Chakavak.Identity.EntityFrameworkCore'...
No design-time services were found.
System.InvalidOperationException: The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.Internal.DirectConstructorBinding'. Configure your services to use one that can.
at Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper.UnknownLiteral(Object value)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateAnnotation(IAnnotation annotation, IndentedStringBuilder stringBuilder)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypeAnnotations(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityType(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder)
at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypes(String builderName, IReadOnlyList
1 entityTypes, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.Generate(String builderName, IModel model, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpMigrationsGenerator.GenerateMetadata(String migrationNamespace, Type contextType, String migrationName, String migrationId, IModel targetModel) at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_1.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0
1.b__0()at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.Internal.DirectConstructorBinding'. Configure your services to use one that can.
`
The text was updated successfully, but these errors were encountered: