Skip to content

Add migration fails with 'Unable to cast object of type 'System.Single' to type 'System.Int32' #18021

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

Closed
dominique-ruest opened this issue Sep 24, 2019 · 2 comments

Comments

@dominique-ruest
Copy link

dominique-ruest commented Sep 24, 2019

Adding a migration fails with 'Unable to cast object of type 'System.Single' to type 'System.Int32'.

Steps to reproduce

Generate an initial migration with entity types having numerical property types. Works fine. Without changes attempt to generate another migration with a new name. The migration fails with the following error:

System.InvalidCastException: Unable to cast object of type 'System.Single' to type 'System.Int32'.
at lambda_method(Closure , ValueBuffer )
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalShadowEntityEntry..ctor(IStateManager stateManager, IEntityType entityType, ValueBuffer& valueBuffer)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryFactory.NewInternalEntityEntry(IStateManager stateManager, IEntityType entityType, Object entity, ValueBuffer& valueBuffer)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntryFactory.Create(IStateManager stateManager, IEntityType entityType, Object entity, ValueBuffer& valueBuffer)
at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.CreateEntry(IDictionary2 values, IEntityType entityType) at Microsoft.EntityFrameworkCore.Update.Internal.UpdateAdapter.CreateEntry(IDictionary2 values, IEntityType entityType)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.TrackData(IModel source, IModel target)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IModel source, IModel target, DiffContext diffContext)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.GetDifferences(IModel source, IModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.ScaffoldMigration(String migrationName, String rootNamespace, String subNamespace, String language)
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_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to cast object of type 'System.Single' to type 'System.Int32'.

Further technical details

EF Core version: 3.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Visual Studio 2019

@smitpatel
Copy link
Contributor

Duplicate of #17851

@smitpatel smitpatel marked this as a duplicate of #17851 Sep 24, 2019
@smitpatel
Copy link
Contributor

Generate an initial migration with entity types having numerical property types. Works fine. Without changes attempt to generate another migration with a new name. The migration fails with the following error:

I tried above and it still worked for me.
@Doumda - Can you provide us a small repro? Model class & Model configuration with has data works.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants