Not able to scaffold with dotnet ef core on mac

.net .net-core c# entity-framework entity-framework-core

Question

I'm trying to use .net core to reverse engineer model classes from existing database on my MAC. The database is running in a VM with windows and I am able to connect to it from osx.

In my project.json I have the following:

"dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.AngularServices": "1.0.0-*",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.1",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",

    "Microsoft.EntityFrameworkCore.Design": {
      "type": "build",
      "version": "1.0.0-preview2-final"
    },
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },

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

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true,
    "compile": {
      "exclude": ["node_modules"]
    }
  }

But when I run

dotnet ef dbcontext scaffold "myDbConnectString" Microsoft.EntityFrameworkCore.SqlServer

I get the following error and I can not get passed this

 An error occurred while calling method 'ConfigureDesignTimeServices' on startup class

'Microsoft.EntityFrameworkCore.Scaffolding.SqlServerDesignTimeServices'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: Could not load type 'Microsoft.Extensions.DependencyInjection.ServiceCollectionExtensions' from assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. System.AggregateException: One or more errors occurred. (Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory' while attempting to activate 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'.) ---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory' while attempting to activate 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType, ServiceProvider serviceProvider) at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary2 dictionary, TKey key, Func3 valueFactory, TArg arg) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable1 schemas, IEnumerable1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable1 schemaFilters, IEnumerable1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.d__1.MoveNext() --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task1.GetResultCore(Boolean waitCompletionNotification) at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args) ---> (Inner Exception #0) System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory' while attempting to activate 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'. at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.PopulateCallSites(ServiceProvider provider, ISet1 callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound) at Microsoft.Extensions.DependencyInjection.ServiceLookup.Service.CreateCallSite(ServiceProvider provider, ISet1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetResolveCallSite(IService service, ISet1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetServiceCallSite(Type serviceType, ISet1 callSiteChain) at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(Type serviceType, ServiceProvider serviceProvider) at System.Collections.Concurrent.ConcurrentDictionaryExtensions.GetOrAdd[TKey,TValue,TArg](ConcurrentDictionary2 dictionary, TKey key, Func3 valueFactory, TArg arg) at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) at Microsoft.EntityFrameworkCore.Design.DatabaseOperations.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable1 schemas, IEnumerable1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.ReverseEngineerAsync(String provider, String connectionString, String outputDir, String dbContextClassName, IEnumerable1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Tools.Cli.DbContextScaffoldCommand.d__1.MoveNext()<--- One or more errors occurred. (Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Scaffolding.IScaffoldingModelFactory' while attempting to activate 'Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineeringGenerator'.)

I have tried to change versions of my dependencies back and forth but with no result. Anyone got any pointers?

1
1
11/17/2016 8:14:27 AM

Accepted Answer

Just got it to work. I updated to .net core 1.1.0 and modified my project.json to use newer versions. Hope this can help someone else

project.json:

"dependencies": {
  "Microsoft.NETCore.App": {
    "version": "1.1.0",
    "type": "platform"
  },
  "Microsoft.AspNetCore.AngularServices": "1.0.0-*",
  "Microsoft.AspNetCore.Diagnostics": "1.1.0",
  "Microsoft.AspNetCore.Mvc": "1.1.0",
  "Microsoft.AspNetCore.Razor.Tools": {
    "version": "1.1.0-preview4-final",
    "type": "build"
  },
  "Microsoft.AspNetCore.Server.IISIntegration": "1.1.0",
  "Microsoft.AspNetCore.Server.Kestrel": "1.1.0",
  "Microsoft.AspNetCore.StaticFiles": "1.1.0",
  "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.1.0",
  "Microsoft.Extensions.Configuration.Json": "1.1.0",
  "Microsoft.Extensions.Configuration.CommandLine": "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.EntityFrameworkCore.Design": {
    "type": "build",
    "version": "1.1.0"
  },
  "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
  "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0"
},

"tools": {
  "Microsoft.AspNetCore.Razor.Tools": "1.1.0-preview4-final",
  "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
  "Microsoft.DotNet.Watcher.Tools": "1.1.0-preview4-final",
  "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
}
0
11/21/2016 10:16:17 PM

Popular Answer

Have you tried using an RTM version of Entity Framework?

{
  "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1",
  "Microsoft.EntityFrameworkCore.SqlServer": "1.0.1"
}


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