The line that matters is:
configBuilder.AddJsonFile(f, true, true);
Here is the full code: var configBuilder = new ConfigurationBuilder();
var configFiles = new[]
{
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "appsettings.json"),
// the files below do not exist, not even the directory - just a fallback
Path.Combine(Environment.GetFolderPath(UserProfile, DoNotVerify), ".tester/appsettings.json"),
Path.Combine(Environment.GetFolderPath(ApplicationData, DoNotVerify), "tester/appsettings.json"),
};
foreach (var f in configFiles)
{
// using the line below works fast like expected
// configBuilder.AddJsonFile(f, true, false);
// HUGE slowdown of app startup with second parameter set to true. Why?
configBuilder.AddJsonFile(f, true, true);
}
var config = configBuilder.Build();
Console.WriteLine("tester");
More details:
https://stackoverflow.com/questions/71179452/c-sharp-configurationbuilder-with-reloadonchange-true-slows-down-app-startup-on