Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF Migrations: The parameter 'frameworkName' cannot be an empty string

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"
}
}
like image 690
Adrian Avatar asked Dec 21 '16 18:12

Adrian


3 Answers

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

like image 52
Ghominejad Avatar answered Sep 18 '22 23:09

Ghominejad


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.

like image 31
nzrytmn Avatar answered Sep 17 '22 23:09

nzrytmn


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.
like image 24
webStuff Avatar answered Sep 18 '22 23:09

webStuff