Reputation: 2161
In my program.cs I have
var config = builder.Configuration;
try
{
config.AddJsonFile("appsettings.json");
}
catch (Exception ex)
{
}
I am getting the exception
'The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was '/appsettings.json'.'
The file appsettings.json is in the root directory of the project and copy to output directory is "Copy always".
I also tried using:
try
{
IConfigurationBuilder config2 = new ConfigurationBuilder().AddJsonFile("appsetting.json");
config2.Build();
}
catch (Exception ex)
{
}
This has the same error. Why is the file not found?
Upvotes: 0
Views: 448
Reputation: 2161
Seems the appsettings.json goes into WWWROOT FOLDER in a Blazor WASM peoject not project root.
Upvotes: 0