WebJobsHostBuilderExtensions.ConfigureWebJobs should not add configuration sources
See original GitHub issueWhen configuring the HostBuilder the order of ConfigureWebJobs and ConfigureAppConfiguration is significant, as ConfigureWebJobs adds “appsettings.json” and environment variables as configuration sources. This can lead to invalid configuration values and unexpected behavior, as the order of configuration sources defined in ConfigureAppConfiguration is not the definitive list of configuration sources.
Repro steps
-
Create a new HostBuilder, call ConfigureAppConfiguration with one or more configuration sources that has values that should take precedence over appsettings.json and/or environment variables
-
Call ConfigureWebJobs on the host builder
-
Access a configuration value (example: in
hostBuilder.ConfigureServices((context, services) => { var configValue = context.Configuration["ExampleValue"]; }
) -
Build and run the Host.
Expected behavior
ConfigureWebJobs should not manipulate configuration sources at all, or at the very least have an option to disable the behavior. Configuration values should appear as defined in ConfigureAppConfiguration.
Actual behavior
The rogue configuration sources are added to the configuration sources and may provide invalid configuration values.
Known workarounds
Call ConfigureWebJobs before ConfigureAppConfiguration. The rogue application sources are still added, but the desired sources takes precedence.
Related information
Issue Analytics
- State:
- Created 5 years ago
- Reactions:24
- Comments:47 (10 by maintainers)
Top GitHub Comments
I just spent a day tracking down why my configuration does not work. I was adding Key Vault configuration and environment specific settings which seemed to be quite easy task but after deployment to Azure it didn’t work. I really didn’t expect that configuring webjobs add appsettings.json on top of my configuration effectively reverting all the specific changes
This is quite old issue, still not fixed, causing unnecessary waste of time and workarounds… 👎
What’s the official stance on this? This behavior is clearly incorrect, as it silently overrides the user defined configuration