diff --git a/src/WebJobs.Extensions.DurableTask/StandardConnectionInfoProvider.cs b/src/WebJobs.Extensions.DurableTask/StandardConnectionInfoProvider.cs index 0a9bcca7d..2597877bf 100644 --- a/src/WebJobs.Extensions.DurableTask/StandardConnectionInfoProvider.cs +++ b/src/WebJobs.Extensions.DurableTask/StandardConnectionInfoProvider.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See LICENSE in the project root for license information. using System; +using System.Linq; using Microsoft.Extensions.Configuration; namespace Microsoft.Azure.WebJobs.Extensions.DurableTask @@ -23,10 +24,40 @@ public StandardConnectionInfoProvider(IConfiguration configuration) this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); } + // This implementation is a clone of `IConfigurationSection.Exists` found here https://github.com/dotnet/runtime/blob/main/src/libraries/Microsoft.Extensions.Configuration.Abstractions/src/ConfigurationExtensions.cs#L78 + // Functions host v1 (.net462 framework) doesn't support this method so we implement a substitute one here. + private bool IfExists(IConfigurationSection section) + { + if (section == null) + { + return false; + } + + if (section.Value == null) + { + return section.GetChildren().Any(); + } + + return true; + } + /// public IConfigurationSection Resolve(string name) { - return this.configuration.GetSection(name); + // This implementation is a replica of the WebJobsConnectionInfoProvider used for the internal durable client. + // The original code can be found at: + // https://github.com/Azure/azure-functions-durable-extension/blob/dev/src/WebJobs.Extensions.DurableTask/WebJobsConnectionInfoProvider.cs#L37. + // We need to first check the configuration section with the AzureWebJobs prefix, as this is the default name within the Functions app whether it's internal or external. + string prefixedConnectionStringName = "AzureWebJobs" + name; + IConfigurationSection section = this.configuration?.GetSection(prefixedConnectionStringName); + + if (!this.IfExists(section)) + { + // If the section doesn't exist, then look for the configuration section without the prefix, since there is no prefix outside the WebJobs app. + section = this.configuration?.GetSection(name); + } + + return section; } } -} \ No newline at end of file +}