Paul Stanley
Paul Stanley

Reputation: 2161

.NET 6 Blazor WASM. Can't Find appsetting.json File

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

Answers (1)

Paul Stanley
Paul Stanley

Reputation: 2161

Seems the appsettings.json goes into WWWROOT FOLDER in a Blazor WASM peoject not project root.

Upvotes: 0

Related Questions