NetCito NetCito - 1 month ago 14
C# Question

Why visual studio tell me that AddJsonFile() method is not define in configuration class?

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 give me an error: 'Configuration' does not contain a definition for 'AddJsonFile'...

What is wrong?.

Answer

You need to include the Microsoft.Framework.ConfigurationModel.Json if you want to call the .AddJsonFile() method

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

For further reading, a nice tutorial is at: http://whereslou.com/2014/05/23/asp-net-vnext-moving-parts-iconfiguration/