When trying to remove a migration in the newest update (EFCore 5 preview 3) I get this exception:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IColumn column, RelationalTypeMapping typeMapping, Boolean isNullable, IEnumerable`1 migrationsAnnotations, Boolean inline)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IColumn source, IColumn target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.HasDifferences(IRelationalModel source, IRelationalModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>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)
Object reference not set to an instance of an object.
The remove-migration command works when downgrading the packages to version 3.1.3
Open Package Manager Console
Run command: remove-migration
PM> remove-migration -v
Using project 'EFCoreMigrationTests'.
Using startup project 'EFCoreMigrationTests'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0\EFCoreMigrationTests.deps.json --additionalprobingpath C:\Users\Mark\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0\EFCoreMigrationTests.runtimeconfig.json C:\Users\Mark\.nuget\packages\microsoft.entityframeworkcore.tools\5.0.0-preview.3.20181.2\tools\netcoreapp2.0\any\ef.dll migrations remove --json --verbose --no-color --prefix-output --assembly D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0\EFCoreMigrationTests.dll --startup-assembly D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0\EFCoreMigrationTests.dll --project-dir D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\ --language C# --working-dir D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests --root-namespace EFCoreMigrationTests
Using assembly 'EFCoreMigrationTests'.
Using startup assembly 'EFCoreMigrationTests'.
Using application base 'D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0'.
Using working directory 'D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests'.
Using root namespace 'EFCoreMigrationTests'.
Using project directory 'D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding Microsoft.Extensions.Hosting service provider...
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'MyContext'.
Using context 'MyContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding design-time services referenced by assembly 'EFCoreMigrationTests'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'EFCoreMigrationTests'...
No design-time services were found.
'MyContext' disposed.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IColumn column, RelationalTypeMapping typeMapping, Boolean isNullable, IEnumerable`1 migrationsAnnotations, Boolean inline)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IColumn source, IColumn target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.HasDifferences(IRelationalModel source, IRelationalModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>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)
Object reference not set to an instance of an object.
Also tested it with the cli gives the same result as the PMC.
EF Core version: 5.0.0-preview.3.20181.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: dotnet 5 preview 3
Operating system:
IDE: 16.6.0 Preview 4.0
Possible related issues:
Is there any known workaround without having to downgrade for now?
The only other way I have found so far is to remove the migrations completely, drop the tables and recreate the migration by running the add-migration command.
Note for team: this fails on current daily build with a different exception. We should understand what test coverage we need to add here, since removing migrations has been regressed several times recently.
ajcvickers@avickers420u:~/Repros/EFCoreMigrationsBug-master$ dotnet ef migrations remove
Build started...
Build succeeded.
System.ArgumentNullException: Value cannot be null. (Parameter 'args')
at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations..ctor(IOperationReporter reporter, Assembly assembly, Assembly startupAssembly, String projectDir, String rootNamespace, String language, String[] args)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.get_MigrationsOperations()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>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)
Value cannot be null. (Parameter 'args')
ajcvickers@avickers420u:~/Repros/EFCoreMigrationsBug-master$
/cc @bricelam for test coverage.
@lajones This looks related to additional arguments work you did recently
This looks like using an old version of the tools with a new version of Microsoft.EntityFramework.Design. Specifically there is no Remaining Arguments line in the verbose output, which there should be with the new tools.
@visschersm can you try uninstalling and re-installing the tools - see this link. And make sure you specify --version 5.0.0-preview3 when re-installing please.
We should handle this. I think I saw a late comment by @smitpatel in the PR that would fix this
Yes. I should guard against it. Assigning to me.
This looks like using an old version of the tools with a new version of
Microsoft.EntityFramework.Design. Specifically there is noRemaining Argumentsline in the verbose output, which there should be with the new tools.@visschersm can you try uninstalling and re-installing the tools - see this link. And make sure you specify
--version 5.0.0-preview3when re-installing please.
uninstalled and re-installed the tools gives the following verbose log:
dotnet exec --depsfile D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0\EFCoreMigrationTests.deps.json --additionalprobingpath C:\Users\Mark\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0\EFCoreMigrationTests.runtimeconfig.json C:\Users\Mark\.dotnet\tools\.store\dotnet-ef\5.0.0-preview.3.20181.2\dotnet-ef\5.0.0-preview.3.20181.2\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll migrations remove --assembly D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0\EFCoreMigrationTests.dll --startup-assembly D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0\EFCoreMigrationTests.dll --project-dir D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\ --language C# --working-dir D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests --verbose --root-namespace EFCoreMigrationTests
Using assembly 'EFCoreMigrationTests'.
Using startup assembly 'EFCoreMigrationTests'.
Using application base 'D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\bin\Debug\net5.0'.
Using working directory 'D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests'.
Using root namespace 'EFCoreMigrationTests'.
Using project directory 'D:\Users\Mark\Documents\GitHub\CSharp\EFCoreMigrationTests\'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding Microsoft.Extensions.Hosting service provider...
No static method 'CreateHostBuilder(string[])' was found on class 'Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'MyContext'.
Using context 'MyContext'.
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding design-time services referenced by assembly 'EFCoreMigrationTests'.
No referenced design-time services were found.
Finding IDesignTimeServices implementations in assembly 'EFCoreMigrationTests'...
No design-time services were found.
'MyContext' disposed.
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Initialize(ColumnOperation columnOperation, IColumn column, RelationalTypeMapping typeMapping, Boolean isNullable, IEnumerable`1 migrationsAnnotations, Boolean inline)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(IColumn source, IColumn target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.Diff(ITable source, ITable target, DiffContext diffContext)+MoveNext()
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.DiffCollection[T](IEnumerable`1 sources, IEnumerable`1 targets, DiffContext diffContext, Func`4 diff, Func`3 add, Func`3 remove, Func`4[] predicates)+MoveNext()
at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsModelDiffer.HasDifferences(IRelationalModel source, IRelationalModel target)
at Microsoft.EntityFrameworkCore.Migrations.Design.MigrationsScaffolder.RemoveMigration(String projectDir, String rootNamespace, Boolean force, String language)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.RemoveMigration(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigrationImpl(String contextType, Boolean force)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.RemoveMigration.<>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)
Object reference not set to an instance of an object.
Getting the same log as @visschersm after uninstalling and installing 5.0.0 preview3 tools. I noticed the messages No referenced design-time services were found and No design-time services were found. in the log. Doesn't mean anything to me but might mean something for the EF team?
For the record, I get the same error when running from command line (dotnet ef) or from package manager console.
@dealdiane No, don't worry about the No Xyz services were found - that's normal.
Note: Looks like this bug was there in 5.0.0-preview.2.20159.4 and 5.0.0-preview.3.20181.2, but was not there in 3.1.3, nor can I see it in our local most up-to-date build (once I apply PR #20799). So far I haven't been able to find which specific update fixed it.
OK, found it. The issue @visschersm and @dealdiane are seeing is already fixed by PR #20652. Unfortunately this just missed the Preview 3 cutoff, but will be available in Preview 4.
The issue in @ajcvickers comment above will be fixed by PR #20799.
Most helpful comment
OK, found it. The issue @visschersm and @dealdiane are seeing is already fixed by PR #20652. Unfortunately this just missed the Preview 3 cutoff, but will be available in Preview 4.
The issue in @ajcvickers comment above will be fixed by PR #20799.