In my Startup.cs file I have the following:
public Startup(IHostingEnvironment env)
{
// Set up configuration sources.
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; set; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
var fooValue = Configuration.Get("foo");
// Add framework services.
services.AddMvc();
}
And in my appsettings.json file I have { "foo": "bar" }
Later in my Startup class I have:
public void ConfigureServices(IServiceCollection services)
{
var fooValue = Configuration.Get("foo");
// Add framework services.
services.AddMvc();
}
I try to watch to value of fooValue change in my Locals debugger by setting a breakpoint on it (VS2015 with the ASP.NET 5 extensions) but I get the following error when I step over it:
An exception of type 'System.InvalidOperationException' occurred in Microsoft.Extensions.Configuration.Binder.dll but was not handled in user code
Additional information: Cannot create instance of type 'System.String' because it is missing a public parameterless constructor.
I'm following the MVA Configuring Data at 18m 53s
I've tried creating a config.json file as in the example, but the template seems to have changed, and it doesn't help anyway.
Should I be allowed to grab configuration info out of .json files like this?