startIndex cannot be larger than length of string. (Parameter 'startIndex')
See original GitHub issueWhen there are existing custom migrations in my Migrations folder and I try to run the command Add-Migration
in the package manager console I receive the following error:
startIndex cannot be larger than length of string. (Parameter 'startIndex')
Build started… Build succeeded. Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 5.0.11 initialized ‘ApiDbContext’ using provider ‘Microsoft.EntityFrameworkCore.SqlServer’ with options: MigrationsAssembly=Infrastructure System.ArgumentOutOfRangeException: startIndex cannot be larger than length of string. (Parameter ‘startIndex’) at System.String.Substring(Int32 startIndex, Int32 length) at System.String.Substring(Int32 startIndex) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsIdGenerator.GetName(String id) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsAssembly.<>c__DisplayClass13_0.<FindMigrationId>b__1(String id) at System.Linq.Enumerable.WhereEnumerableIterator 1.MoveNext() at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable 1 source, Boolean& found) at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable 1 source) at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationsAssembly.FindMigrationId(String nameOrId) 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, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType, String namespace) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>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) startIndex cannot be larger than length of string. (Parameter ‘startIndex’)
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
I managed to reproduce this! I was running mismatched versions of Microsoft.EntityFrameworkCore and Microsoft.EntityFrameworkCore.Design (specifically 7.0.0-preview.6.22329.4 and 6.0.7, respectively). I can’t say that the original poster had the exact same root cause, but if you run into the same problem, check your nuget packages!
@fairking See #27115.