ef-core Add-Migration not working

.net-core ef-migrations entity-framework-core


just started learning dot net core 2.0.

when i try to create migration:

PM> Add-Migration InitialModel

i get error:

Add-Migration : Exception calling "Substring" with "1" argument(s): "StartIndex cannot be less than zero. Parameter name: startIndex" At line:1 char:1 + Add-Migration InitialModel + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Migration], MethodInvocationException + FullyQualifiedErrorId : ArgumentOutOfRangeException,Add-Migration

my dotnet --info

.NET Command Line Tools (2.0.0)

Product Information: Version: 2.0.0 Commit SHA-1 hash: cdcd1928c9

Runtime Environment: OS Name: Windows OS Version: 10.0.15063 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.0.0\

Microsoft .NET Core Shared Framework Host

Version : 2.0.0 Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

my csproj file:


    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />

    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />

thanks for help!

8/22/2017 9:00:24 AM

Accepted Answer

I have seen this error occur if the v1.x version of the PMC (Package Manager Console) migration commands are loaded in Visual Studio and then you try to run the commands against a v2.x application. E.g. if you create or open an ASP.NET Core 1.1 application and then you create an ASP.NET Core 2.0 application in the same Visual Studio session.

The workaround for this case is to re-start Visual Studio before you work with the 2.0 application.

According to bricelam there is a mechanism in NuGet that should cause the load of the newer version of the PMC commands into Visual Studio but unfortunately the mechanism is not triggered in all cases.

1/23/2018 8:21:51 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow