8

I'm following some tutorials on plural sight on how to setup my first web api using .netcore. I'm having an issue trying to run my first migration:

PM> Add-Migration InitialMigration Exception calling ".ctor" with "1" argument(s): "The parameter 'frameworkName' cannot be an empty string. Parameter name: frameworkName"

I understand it's saying there is a constructor somewhere with one argument that is empty; however, I have no idea where this "frameworkName" parameter is. I'm assuming it's some internal EF mechanism.

What class is this error message referencing?

This is my simple entity setup

public class ShackupContext : DbContext
{
    public DbSet<Post> Posts { get; set; }
    public ShackupContext(DbContextOptions<ShackupContext> options):base(options)
    {

    }
}  


    public class Post
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }
    [Required]
    [MaxLength(200)]
    public string Name { get; set; }
}  

UPDATE 1 I have updated my dbcontext to call the base class constructor as @ViktorsTelle suggested.

My project is setup different than any tutorials I have followed. The main difference is my entities are contained in their own project as opposed to being in the api project itself.
enter image description here
This led me to believe that running Add-Migration on the Shackup.Data project itself did not require me to register my dbcontext inside of my api project. I did it anyway to see what would happen:

 public void ConfigureServices(IServiceCollection services)
    {
        // Add framework services.
        services.AddMvc();
        services.AddDbContext<ShackupContext>(o => 
        o.UseNpgsql(Configuration["connectionStrings:postgres"],
        a => a.MigrationsAssembly("Shackup.Data")));
    }  

Once I did that I managed to get a little further in the migration process. I am now getting
PM> Add-Migration InitialMigration The specified deps.json [C:\Users\campo\Documents\Visual Studio 2015\Projects\Shackup\src\Shackup.Api\bin\Debug\netcoreapp1.1\Shackup.Api.deps.json] does not exist Process finished with non-zero exit code

So I took a look at that directory and indeed it was missing the file; however, the file is being output to a child folder of that directory.

enter image description here

The deps.json file is located inside the win10-x64 folder. I can simply copy and paste to the required folder but now I am faced with a new question:

Why is Nuget package manager console looking in the wrong directory?
Or possibly: How can I change this to look in the correct place?

Update 2

I have updated all my project dependencies in both projects. Here are the two files for the data and the api projects below

API

{
"dependencies": {
"Microsoft.AspNetCore.Mvc": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.1.0",
"Microsoft.Extensions.Configuration.Json": "1.1.0",
"Microsoft.Extensions.Logging": "1.1.0",
"Microsoft.Extensions.Logging.Console": "1.1.0",
"Microsoft.Extensions.Logging.Debug": "1.1.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.1.0",
"Microsoft.NETCore.App": "1.1.0",
"Shackup.Data": "1.0.0-*",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.1.0",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final"
},

"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
},

"frameworks": {
"netcoreapp1.1": {
  "imports": [
    "dotnet5.6",
    "portable-net45+win8"
  ]
}
},

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"runtimeOptions": {
"configProperties": {
  "System.GC.Server": true
}
},
"runtimes": {
"win10-x64": {},
"win81-x64": {}
},

"publishOptions": {
"include": [
  "wwwroot",
  "**/*.cshtml",
  "appsettings.json",
  "web.config"
]
},

"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}  

DATA

{
"version": "1.0.0-*",

"dependencies": {
"Microsoft.EntityFrameworkCore": "1.1.0",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
"NETStandard.Library": "1.6.1"
},

 "frameworks": {
"netstandard1.6": {
  "imports": "dnxcore50"
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
}
}
19
  • The first thing that I have noticed is the lack of base class call in constructor. Please add : base(options) to constructor. Dec 21, 2016 at 18:57
  • Which version of Visual Studio and specially NuGet are you using? You will need VS 2015 Update 3 and NuGet v 3.5 to use .NET Core EF commands Dec 21, 2016 at 19:02
  • Hello, I do have v. 3.5 nuget as well as VS2015 Enterprise Update 3: 14.0.25431.01
    – Adrian
    Dec 21, 2016 at 19:06
  • 1
    To your last edit, don't you need Npgsql.EntityFrameworkCore.PostgreSQL.Design ? Dec 21, 2016 at 19:23
  • 1
    And... change the imports section to depend on dnxcore50 instead of dotnet5.6 Dec 21, 2016 at 19:38

3 Answers 3

18

Select proper Startup Project in your solution : Right-click on your project in the solution explorer, select "Set as startup project"

0
4

Select the project that your entities included as Startup Project (Right-click on your project in the solution explorer and select "Set as startup project") and be sure that you installed Microsoft.EntityFrameworkCore.Design package. May be this is not best solution but solved my same problem.

1

In my case, brand new .Net Core 2.2 MVC app, the issue was resolved by selecting a startup object:

  1. Right-click on your app
  2. Choose 'Properties'
  3. In the 'Application' tab, the "Startup object" dropdown list had the value "(Not set)". Selecting the (only) other available item "MyAppName.Program" did the trick for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.