MVC6 error The name 'Configuration' does not exist in the current context

asp.net-core asp.net-mvc c# entity-framework-6

Question

I have attempted to re-write my DbContext from EF Core to EF6 to work with my supported database by following the following documentation: https://docs.asp.net/en/latest/data/entity-framework-6.html

However I receive the error The name 'Configuration' does not exist in the current context based on the following line of code in my Startup.cs:

services.AddScoped((_) => new PortalUserContext(Configuration["Data:DefaultConnection:ConnectionString"]));

UPDATE

I have added the System.Configuration.dll to the solution's references which causes a new error 'Configuration' is a type, which is not valid in the given context NextGenPortal `

1
2
9/16/2016 5:01:32 AM

Popular Answer

I ran into a similar issue when trying to add Configuration to an asp.net core project. I eventually ran into this blog post that explains how to define that Configuration property, which for some strange reason is not covered in the asp.net core documentation.

http://www.mikesdotnetting.com/article/284/asp-net-5-configuration

Basically you need to define this property in your Startup class and then instantiate it in the constructor with the corresponding config file. The article is a bit outdated but it's easier to figure out the parts that changed. Like the signature for the Startup constructor.

1
9/29/2016 4:05:11 AM


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