Entity Framework Core Scaffolding Access To Method Failed

asp.net-core asp.net-core-1.1 entity-framework-core

Question

After running following command:

dotnet ef dbcontext scaffold
"Server=SERVERNAME;Database=MYDATABASE;Trusted_Connection=True;"
Microsoft.EntityFrameworkCore.SqlServer -o Models -f

I get this error:

One or more errors occurred. (Attempt by method 'Microsoft.EntityFrameworkCore.Scaffolding.Configuration.Internal.ModelConfiguration.get_EntityConfigurations()' to access method 'Microsoft.EntityFra meworkCore.Metadata.Internal.EntityTypeNameComparer..ctor()' failed.)

project.json:

{
  "userSecretsId": "aspnet-APPLICATION-0799fe3e-6eaf-4c5f-b40e-7c6bfd5dfa9a",
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.1.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Routing": "1.0.1",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.1.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-update1",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-update1",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
    "Microsoft.Extensions.Logging.Abstractions": "1.1.0",
    "Newtonsoft.Json": "9.0.1",
    "Microsoft.AspNetCore.Mvc.Versioning": "1.0.2"
  },
  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    },
    "Microsoft.Extensions.SecretManager.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8+dnxcore50",
        "portable-net45+win8"
      ]
    }
  },
  "frameworks": {
    "netcoreapp1.1": {
      "imports": [
        "dotnet5.6",
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },
  "buildOptions": {
    "debugType": "portable",
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "appsettings.json",
      "web.config"
    ]
  },
  "scripts": {
    "prepublish": [
      "npm install",
      "bower install",
      "gulp clean",
      "gulp min"
    ],
    "postpublish": [
      "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
    ]
  },
  "tooling": {
    "defaultNamespace": "APPLICATION"
  }
}

Dotnet Version: 1.0.0-preview2-1-003177

It is becoming impossible to track all the versions and make them work together.

1
3
11/19/2016 2:17:21 AM

Accepted Answer

So the solution is:

"dependancies":{
   "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
}

"tools": {
   "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
   "Microsoft.EntityFrameworkCore.Tools.DotNet": " 1.1.0-preview4-final"
},
9
11/19/2016 3:08:47 AM

Popular Answer

I got all kinds of errors until I installed the .NET Core 1.1 SDK.

https://www.microsoft.com/net/download/core#/current

And yes - the filename for the 1.1 release is dotnet-dev-win-x64.1.0.0-preview2-1-003177.exe

Before and after for me

C:\Users\SimonWeaver>dotnet --version
1.0.0-preview2-003131

C:\Users\SimonWeaver>dotnet --version
1.0.0-preview2-1-003177

Now tooling works fine for scaffolding.

Looking back again I see you had this installed already but I'll leave this here in case anybody else doesn't.



Related Questions





Related

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