question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add-Migration exception - The current CSharpHelper cannot scaffold literals of type 'System.Func`3

See original GitHub issue

Exception is thrown when adding new migration to the project. Why?

Steps to reproduce

Open following project and try to add new migration.

This is new Web App project, I’ve just added some entities classes.

The issue

When trying to add a new migration including MessageBase and InvitationMessage entities, following exception is thrown:

Exception message: The current CSharpHelper cannot scaffold literals of type ‘System.Func`3[Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.IEntityType,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator]’. Configure your services to use one that can.

Stack trace: System.InvalidOperationException: The current CSharpHelper cannot scaffold literals of type 'System.Func3[Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.IEntityType,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator]'. Configure your services to use one that can. at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpHelper.UnknownLiteral(Object value) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateAnnotation(IAnnotation annotation, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateAnnotations(IReadOnlyList1 annotations, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GeneratePropertyAnnotations(IProperty property, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateProperty(IProperty property, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateProperties(IEnumerable1 properties, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityType(String builderName, IEntityType entityType, IndentedStringBuilder stringBuilder) at Microsoft.EntityFrameworkCore.Migrations.Design.CSharpSnapshotGenerator.GenerateEntityTypes(String builderName, IReadOnlyList1 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.MigrationsOperations.AddMigration(String name, String outputDir, String contextType) at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action1 reporter) at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.<>c__DisplayClass0_0.<Configure>b__0() at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) The current CSharpHelper cannot scaffold literals of type 'System.Func3[Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.EntityFrameworkCore.Metadata.IEntityType,Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator]'. Configure your serv ices to use one that can.

Further technical details

Operating system: WIN10 Visual Studio version: VS 2015

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
fernandoantunessilvacommented, Feb 21, 2019

Try upgrading the EF tools packages to 1.0.0-preview3-final and installing the 1.1.0 version of Microsoft.EntityFrameworkCore.Design. I don’t think preview2 works with 1.1.

After install “Microsoft.EntityFrameworkCore.Design” work for me, thanks

1reaction
smitpatelcommented, Nov 26, 2017

The point is, even if you put that annotation in EF model, EF does not understand it and will not do anything around it apart from throwing exception when it needs to print it out. If you are trying to use annotations for validation then you should put annotations on classes rather than in EF model. EF does not do any validation. Other validation frameworks based on annotations are required to do due processing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EF Core 1.1 Migration - The current CSharpHelper cannot ...
The current CSharpHelper cannot scaffold literals of type 'System.Func`3[Microsoft.EntityFrameworkCore.Metadata.IProperty,Microsoft.
Read more >
Migrations Error – cannot scaffold literals of type ...
From the Package Manager Console, I type add-migration initial . I then get the following error: The current CSharpHelper cannot scaffold literals of...
Read more >
EF Core 1.1 Migration - The current CSharpHelper cannot ...
Coding example for the question EF Core 1.1 Migration - The current CSharpHelper cannot scaffold literals of type-Entity Framework.
Read more >
Debugging Entity Framework Core migration scaffolding and ...
NET exception is thrown to investigate the issues in-depth. Debugging migration scaffolding. This is a tiny bit more complicated, but it's also ...
Read more >
Getting this error when adding migration.
The current CSharpHelper cannot scaffold literals of type 'Microsoft.EntityFrameworkCore.Metadata.Internal.DirectConstructorBinding'.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found