diff --git a/src/libraries/Microsoft.Extensions.Configuration.FileExtensions/src/FileConfigurationProvider.cs b/src/libraries/Microsoft.Extensions.Configuration.FileExtensions/src/FileConfigurationProvider.cs index f84ed8ead309ef..fa9f59683c9427 100644 --- a/src/libraries/Microsoft.Extensions.Configuration.FileExtensions/src/FileConfigurationProvider.cs +++ b/src/libraries/Microsoft.Extensions.Configuration.FileExtensions/src/FileConfigurationProvider.cs @@ -6,7 +6,7 @@ using System.IO; using System.Runtime.ExceptionServices; using System.Text; -using System.Threading; +using System.Threading.Tasks; using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.Primitives; @@ -33,10 +33,21 @@ public FileConfigurationProvider(FileConfigurationSource source) { _changeTokenRegistration = ChangeToken.OnChange( () => Source.FileProvider.Watch(Source.Path!), - () => + async () => { - Thread.Sleep(Source.ReloadDelay); - Load(reload: true); + await Task.Delay(Source.ReloadDelay).ConfigureAwait(false); + try + { + Load(reload: true); + } + catch + { + // Load already surfaces reload failures through the + // FileConfigurationSource.OnLoadException callback. Any exception that + // escapes here is usually swallowed by OnChange or by the FileProvider, + // so swallow it here instead, to make it clear this is the intended behavior + // and to make it more consistent. + } }); } }