Skip to content

.NET CORE SDK 3.0.100 - EF Migration Failed #1

@vinothkt

Description

@vinothkt

When developing this project using .NET Core SDK (3.0.100-preview6-012264), I am getting below migration error upon running this command "dotnet ef migrations add AddCommandsToDB -v"

Issues:

Using project 'E:\C#API\CommandAPI\CommandAPI.csproj'.
Using startup project 'E:\C#API\CommandAPI\CommandAPI.csproj'.
Writing 'E:\C#API\CommandAPI\obj\CommandAPI.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\vinot\AppData\Local\Temp\tmpFD55.tmp /verbosity:quiet /nologo E:\C#API\CommandAPI\CommandAPI.csproj
Writing 'E:\C#API\CommandAPI\obj\CommandAPI.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\vinot\AppData\Local\Temp\tmp2A5.tmp /verbosity:quiet /nologo E:\C#API\CommandAPI\CommandAPI.csproj
dotnet build E:\C#API\CommandAPI\CommandAPI.csproj /verbosity:quiet /nologo

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:03.28
dotnet exec --depsfile E:\C#API\CommandAPI\bin\Debug\netcoreapp3.0\CommandAPI.deps.json --additionalprobingpath C:\Users\vinot.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig E:\C#API\CommandAPI\bin\Debug\netcoreapp3.0\CommandAPI.runtimeconfig.json C:\Users\vinot.nuget\packages\dotnet-ef\3.0.0-preview6.19304.10\tools\netcoreapp3.0\any\tools\netcoreapp2.0\any\ef.dll migrations add AddCommandsToDB --assembly E:\C#API\CommandAPI\bin\Debug\netcoreapp3.0\CommandAPI.dll --startup-assembly E:\C#API\CommandAPI\bin\Debug\netcoreapp3.0\CommandAPI.dll --project-dir E:\C#API\CommandAPI\ --language C# --working-dir E:\C#API\CommandAPI --verbose --root-namespace CommandAPI
Using assembly 'CommandAPI'.
Using startup assembly 'CommandAPI'.
Using application base 'E:\C#API\CommandAPI\bin\Debug\netcoreapp3.0'.
Using working directory 'E:\C#API\CommandAPI'.
Using root namespace 'CommandAPI'.
Using project directory 'E:\C#API\CommandAPI'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding IWebHost accessor...
No CreateWebHostBuilder(string[]) method was found on type 'CommandAPI.Program'.
No application service provider was found.
Finding DbContext classes in the project...
Found DbContext 'CommandContext'.
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'CommandContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728 ---> System.MissingMethodException: No parameterless constructor defined for type 'CommandAPI.Models.CommandContext'.
at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type, Boolean nonPublic, Boolean wrapExceptions)
at System.Activator.CreateInstance(Type type)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass12_3.b__13()
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.<>c__DisplayClass12_3.b__13()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func1 factory) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType) 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_1.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_01.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to create an object of type 'CommandContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

Programs.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace CommandAPI
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}

    public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
            .ConfigureWebHostDefaults(webBuilder =>
            {
                webBuilder.UseStartup<Startup>();
            });
}

}

Note: I am trying to use MySQL DB:

"Data":
{
"CommandAPIConnection":
{
"ConnectionString" : "Server=localhost;port=3306;user=root;Database=CommandAPI;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}

.csproj

netcoreapp3.0 ---------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions