I'm working on MVC6 webapp. My Startup.cs has the following code-
public class Startup
{
public static Microsoft.Framework.ConfigurationModel.IConfiguration Configuration { get; set; }
public Startup(IHostingEnvironment env)
{
//following line throws NullReferenceException
Configuration = new Configuration().AddJsonFile("config.json").AddEnvironmentVariables();
}
}
config.json-
{
"Data": {
"DefaultConnection": {
"ConnectionString": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted_Connection=True;"
}
}
}
Any help?
UPDATE: This question is not all about NullReferenceException. In ASP.NET-5 MVC-6, config.json is a new addition. I am using the code as it is found in several blogs. Here are few links-
- http://bitoftech.net/2014/11/18/getting-started-asp-net-5-mvc-6-web-api-entity-framework-7/
- https://github.com/aspnet/MusicStore/blob/master/src/MusicStore/Startup.cs
- http://forums.asp.net/t/1999143.aspx?How+to+configure+connection+string+in+MVC+6+in+ASP+NET+vNext
- http://blog.developers.ba/read-config-file-in-asp-net-vnext/