Skip to content
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

Unable to cast object of type 'Microsoft.EntityFrameworkCore.Infrastructure.Annotation' to type 'Microsoft.EntityFrameworkCore.Metadata.IConventionAnnotation' #24658

Closed
ooples opened this issue Apr 14, 2021 · 3 comments · Fixed by #24688
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@ooples
Copy link

ooples commented Apr 14, 2021

I'm getting this exception when performing the dbscaffold context command in the package manager console using Entity Framework Core 6.0.0-preview.3.21201.2

Build started...
Build succeeded.
To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263.

System.InvalidCastException: Unable to cast object of type 'Microsoft.EntityFrameworkCore.Infrastructure.Annotation' to type 'Microsoft.EntityFrameworkCore.Metadata.IConventionAnnotation'.
   at Microsoft.EntityFrameworkCore.Infrastructure.ConventionAnnotatable.OnAnnotationSet(String name, Annotation annotation, Annotation oldAnnotation)
   at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.SetAnnotation(String name, Annotation annotation, Annotation oldAnnotation)
   at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.AddAnnotation(String name, Annotation annotation)
   at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.AddAnnotations(AnnotatableBase annotatable, IEnumerable`1 annotations)
   at Microsoft.EntityFrameworkCore.Infrastructure.AnnotatableBase.AddAnnotations(IEnumerable`1 annotations)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndex(EntityTypeBuilder builder, DatabaseIndex index)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndexes(EntityTypeBuilder builder, ICollection`1 indexes)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection`1 tables)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(DatabaseModel databaseModel, ModelReverseEngineerOptions options)
   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluarlize)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

Unable to cast object of type 'Microsoft.EntityFrameworkCore.Infrastructure.Annotation' to type 'Microsoft.EntityFrameworkCore.Metadata.IConventionAnnotation'.

@roji
Copy link
Member

roji commented Apr 14, 2021

@ooples can you provide more details? Can you please post your csproj, and specify which database you're trying to scaffold?

@AndriySvyryd AndriySvyryd self-assigned this Apr 19, 2021
@AndriySvyryd AndriySvyryd added this to the 6.0.0 milestone Apr 19, 2021
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 19, 2021
@AndriySvyryd AndriySvyryd removed their assignment Apr 19, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-preview5 Apr 26, 2021
@ajcvickers
Copy link
Contributor

@Pilchie Any time to get this in preview 4? It looks like reverse engineering with the Power Tools is broken without this fix. If there's a chance, I'll bring it to Tactics.

@Pilchie
Copy link
Member

Pilchie commented Apr 26, 2021

Yes, let's discuss it in Tactics tomorrow. There should be an opportunity through this week at least.

ajcvickers added a commit that referenced this issue Apr 27, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview5, 6.0.0-preview4 Apr 28, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-preview4, 6.0.0 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants