Microsoft.Azure.WebJobs SDK for creating Azure Functions has issues in reading local.settings.json if IConfiguration overrode by custom configuration. #82589
Can this note or warning can be update in the document as appropriate. Initially posted in the Function-Host repo -
Repro steps
Step A: Create a function app,
Step B: Add Queue Trigger functions,
Step C: Add code to use Dependency injection,
Step D: Create an empty IConfiguration using -
IConfiguration configuration = new ConfigurationBuilder().Build();
....
builder.Services.AddSingleton<IConfiguration>(configuration);
Step E: After overridden default configuration all functions (Queue, Timer, etc.) expecting Connection strings from local.settings.json or from the environment variables will start failing.
A host error has occurred during startup operation '4a5fff7d-95bd-4f2f-933c-eb0f789b3e6c'. [2020-10-10T03:08:59.833] Microsoft.Azure.WebJobs.Extensions.DurableTask: Unable to find an Azure Storage connection string to use for this binding.
Expected behavior
After investigation, I found out that all the required settings (cron, connection strings) on which function binding depends are not only driven from environment variables values but these environment variables must be available in Configuration injected or available through DI.
then MyQueueConnection must be available in the Configuration section with the same name. But after injected a configuration excepting environment variables, it starts failing.
Actual behavior
This warning or note must be mentioned in the default templates or on documentation as while overriding the Configuration in DI then there should be AddEnvironmentVariables() injected or the required settings must be manually added as configuration sections under IConfiguration.
For this specific e.g.
IConfiguration configuration = new ConfigurationBuilder().AddEnvironmentVariables().Build();
Known workarounds
Make sure to check Configuration available in DI must have required binding settings.
Related information
Provide any related information
Programming language used: C#
Links to source
Bindings used: Queue/Timer
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
ID: 5786402e-9d88-5de0-607a-1c2a143af006
Version Independent ID: 15368d1c-b22e-7eb2-413f-cc0d41d2b909
@v-anvari Thanks for your comment. Can you please share the document you were referring to where the changes needs to be done so that I can redirect to appropriate team?
Can this note or warning can be update in the document as appropriate. Initially posted in the Function-Host repo -
Repro steps Step A: Create a function app, Step B: Add Queue Trigger functions, Step C: Add code to use Dependency injection, Step D: Create an empty IConfiguration using -
Step E: After overridden default configuration all functions (Queue, Timer, etc.) expecting Connection strings from local.settings.json or from the environment variables will start failing.
A host error has occurred during startup operation '4a5fff7d-95bd-4f2f-933c-eb0f789b3e6c'. [2020-10-10T03:08:59.833] Microsoft.Azure.WebJobs.Extensions.DurableTask: Unable to find an Azure Storage connection string to use for this binding.
Expected behavior After investigation, I found out that all the required settings (cron, connection strings) on which function binding depends are not only driven from environment variables values but these environment variables must be available in Configuration injected or available through DI.
Example:
If I have a Queue trigger with like:
then
MyQueueConnection
must be available in the Configuration section with the same name. But after injected a configuration excepting environment variables, it starts failing.Actual behavior This warning or note must be mentioned in the default templates or on documentation as while overriding the Configuration in DI then there should be AddEnvironmentVariables() injected or the required settings must be manually added as configuration sections under IConfiguration.
For this specific e.g.
IConfiguration configuration = new ConfigurationBuilder().AddEnvironmentVariables().Build(); Known workarounds Make sure to check Configuration available in DI must have required binding settings.
Related information Provide any related information
Programming language used: C# Links to source Bindings used: Queue/Timer
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.