{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7175","repository_url":"https://api.github.com/repos/aspnet/EntityFramework","labels_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7175/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7175/comments","events_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7175/events","html_url":"https://github.com/aspnet/EntityFramework/issues/7175","id":193255602,"number":7175,"title":"An error occurred while calling method 'ConfigureServices' on startup class 'MyApp.Data.Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: The path must be absolute.","user":{"login":"john-luke-laue","id":1404286,"avatar_url":"https://avatars.githubusercontent.com/u/1404286?v=3","gravatar_id":"","url":"https://api.github.com/users/john-luke-laue","html_url":"https://github.com/john-luke-laue","followers_url":"https://api.github.com/users/john-luke-laue/followers","following_url":"https://api.github.com/users/john-luke-laue/following{/other_user}","gists_url":"https://api.github.com/users/john-luke-laue/gists{/gist_id}","starred_url":"https://api.github.com/users/john-luke-laue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/john-luke-laue/subscriptions","organizations_url":"https://api.github.com/users/john-luke-laue/orgs","repos_url":"https://api.github.com/users/john-luke-laue/repos","events_url":"https://api.github.com/users/john-luke-laue/events{/privacy}","received_events_url":"https://api.github.com/users/john-luke-laue/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-12-03T01:27:52Z","updated_at":"2016-12-05T17:29:03Z","closed_at":null,"body":"### Steps to reproduce\r\nI put my DbContext in a separate project from my .NET Core MVC app. The MVC references it. \r\nThe app works just fine and I was able to scaffold the existing database. However, when I want to run a new migration, I get the error: _An error occurred while calling method 'ConfigureServices' on startup class 'MyApp.Data.Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: The path must be absolute._\r\n\r\n\r\nStartup.cs\r\n```\r\npublic class Startup\r\n    {\r\n        public IConfiguration Configuration { get; set; }\r\n\r\n        public Startup(IHostingEnvironment env)\r\n        {\r\n            var config = new ConfigurationBuilder().SetBasePath(\"../MyAppMvc\");\r\n            config.AddJsonFile(\"Config/config.json\");\r\n            config.AddJsonFile($\"Config/config.{env.EnvironmentName}.json\", true);\r\n            config.AddEnvironmentVariables();\r\n            Configuration = config.Build();\r\n        }\r\n\r\n        public void ConfigureServices(IServiceCollection services)\r\n        {\r\n            services.AddDbContext<MyAppContext>(options =>\r\n               options.UseSqlServer(Configuration[\"ConnectionStrings:MyAppDb\"],\r\n               opt => opt.UseRowNumberForPaging()));\r\n        }\r\n    }\r\n\r\n```\r\n\r\nMyAppContext.cs\r\n```\r\n    public partial class MyAppContext : DbContext\r\n    {\r\n        public MyAppContext()\r\n        {\r\n        }\r\n\r\n        public MyAppContext(DbContextOptions<MyAppContext> options) : base(options)\r\n        {\r\n        }\r\n\r\n        protected override void OnModelCreating(ModelBuilder modelBuilder)\r\n        {\r\n             //......\r\n        }\r\n    }\r\n```\r\n\r\n\r\n### The issue\r\nfrom cmd running `dotnet ef migrations add --context MyAppContext NewMigration`\r\n\r\n\r\n```\r\nC:\\Users\\john-luke.laue\\repositories\\MyApp\\src\\MyApp.Data>dotnet ef migrations add --context MyAppContext NewMigration\r\nProject MyApp.Data (.NETFramework,Version=v4.6.1) will be compiled because inputs were modified\r\nCompiling MyApp.Data for .NETFramework,Version=v4.6.1\r\nCompilation succeeded.\r\n    0 Warning(s)\r\n    0 Error(s)\r\nTime elapsed 00:00:07.3036587\r\n\r\nAn error occurred while calling method 'ConfigureServices' on startup class 'MyApp.Data.Startup'. Consider using IDbContextFactory to override the initialization of the DbContext at design-time. Error: The path must be absolute.\r\nParameter name: root\r\nSystem.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.\r\n   at Microsoft.EntityFrameworkCore.Internal.DatabaseProviderSelector.SelectServices()\r\n   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.<Initialize>b__6_0()\r\n   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()\r\n   at Microsoft.EntityFrameworkCore.Internal.DbContextServices.get_DatabaseProviderServices()\r\n   at Microsoft.EntityFrameworkCore.Infrastructure.EntityFrameworkServiceCollectionExtensions.<>c.<AddEntityFramework>b__0_7(IServiceProvider p)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceLookup.FactoryService.Invoke(ServiceProvider provider)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceProvider.ScopedCallSite.Invoke(ServiceProvider provider)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceProvider.<>c__DisplayClass12_0.<RealizeService>b__0(ServiceProvider provider)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)\r\n   at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)\r\n   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(DbContext context)\r\n   at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)\r\n   at Microsoft.EntityFrameworkCore.Design.Internal.OperationExecutor.AddMigration(String name, String outputDir, String contextType)\r\n   at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.Execute(CommonOptions commonOptions, String name, String outputDir, String context, String environment, Action`1 reporter)\r\n   at Microsoft.EntityFrameworkCore.Tools.Cli.MigrationsAddCommand.<>c__DisplayClass0_0.<Configure>b__0()\r\n   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)\r\n   at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)\r\nNo database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.\r\n```\r\n\r\n### Further technical details\r\n\r\nproject.json\r\n```\r\n{\r\n  \"version\": \"1.0.0-*\",\r\n  \"buildOptions\": {\r\n    \"emitEntryPoint\": true,\r\n    \"warningsAsErrors\": true\r\n  },\r\n\r\n  \"dependencies\": {\r\n    \"Microsoft.AspNetCore.Hosting.Abstractions\": \"1.0.0\",\r\n    \"Microsoft.EntityFrameworkCore\": \"1.0.0\",\r\n    \"Microsoft.EntityFrameworkCore.SqlServer\": \"1.0.0\",\r\n    \"Microsoft.Extensions.Configuration\": \"1.0.0\",\r\n    \"Microsoft.Extensions.Configuration.EnvironmentVariables\": \"1.0.0\",\r\n    \"Microsoft.Extensions.Configuration.FileExtensions\": \"1.0.0\",\r\n    \"Microsoft.Extensions.Configuration.Json\": \"1.0.0\",\r\n    \"Microsoft.Extensions.DependencyInjection.Abstractions\": \"1.0.0\",\r\n    \"Microsoft.EntityFrameworkCore.SqlServer.Design\": \"1.0.0\",\r\n    \"Microsoft.EntityFrameworkCore.Design\" : \"1.0.0-preview2-final\"\r\n  },\r\n\r\n  \"frameworks\": {\r\n    \"net461\": {}\r\n  },\r\n\r\n  \"tools\": {\r\n    \"Microsoft.EntityFrameworkCore.Tools\": \"1.0.0-preview2-final\"\r\n  }\r\n}\r\n\r\n```\r\n\r\nEF Core version: Microsoft.EntityFrameworkCore 1.0.0\r\nOperating system: Windows 10\r\nVisual Studio version: (e.g. VS 2015\r\n\r\nAny help would be appreciated!"},"comment":{"url":"https://api.github.com/repos/aspnet/EntityFramework/issues/comments/264918779","html_url":"https://github.com/aspnet/EntityFramework/issues/7175#issuecomment-264918779","issue_url":"https://api.github.com/repos/aspnet/EntityFramework/issues/7175","id":264918779,"user":{"login":"ajcvickers","id":1430078,"avatar_url":"https://avatars.githubusercontent.com/u/1430078?v=3","gravatar_id":"","url":"https://api.github.com/users/ajcvickers","html_url":"https://github.com/ajcvickers","followers_url":"https://api.github.com/users/ajcvickers/followers","following_url":"https://api.github.com/users/ajcvickers/following{/other_user}","gists_url":"https://api.github.com/users/ajcvickers/gists{/gist_id}","starred_url":"https://api.github.com/users/ajcvickers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ajcvickers/subscriptions","organizations_url":"https://api.github.com/users/ajcvickers/orgs","repos_url":"https://api.github.com/users/ajcvickers/repos","events_url":"https://api.github.com/users/ajcvickers/events{/privacy}","received_events_url":"https://api.github.com/users/ajcvickers/received_events","type":"User","site_admin":false},"created_at":"2016-12-05T17:29:03Z","updated_at":"2016-12-05T17:29:03Z","body":"@john-luke-laue You may also need to remove the parameterless constructor from MyAppContext. See #6826. "}}
{"actor":{"display_login":"ajcvickers"}}