Why does Visual Studio tell me that the AddJsonFile() method is not defined?

NetCito picture NetCito · Dec 9, 2014 · Viewed 58.6k times · Source

I'm developing an ASP.NET 5 WebAPI project using VS Ultimate 2015 Preview. I'm trying to configure the app in this way (line numbers are just guides):

1 using Microsoft.Framework.ConfigurationModel;
2
3 public IConfiguration Configuration { get; private set; }
4 
5 public Startup()
6 {
7     Configuration = new Configuration()
8         .AddJsonFile("config.json")
9         .AddEnvironmentVariables();
10 }

Line 8 gives me an error: 'Configuration' does not contain a definition for 'AddJsonFile'...

What is wrong?

Answer

Lonig picture Lonig · Dec 9, 2014

You need to include the Microsoft.Extensions.Configuration.Json NuGet package if you want to call the .AddJsonFile() method.

See: https://github.com/aspnet/Configuration/tree/dev/src/Microsoft.Framework.ConfigurationModel.Json

For further reading, here's a nice tutorial: ASP.NET vNext Moving Parts: IConfiguration.