Azure / Azure/azure-functions-host
ConnectionStrings don't get bound via [AppSetting] since 2.0.1151-alpha
- Dominant language
- C#
- Stars
- 2k
- Forks
- 482
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 38
Description
All releases since `2.0.11651-alpha` of the functions runtime in Azure don't bind `[AppSetting("ConnectionStrings:CONNECTION_STRING_NAME")]` anymore. It did before that and still does when running locally on latest SDK.
## Investigative information
I've created a minimum representation of the issue to illustrate.
### Doesn't work
- Timestamp: `2018-06-10 07:35:00.006`
- Function App version (1.0 or 2.0-beta): `2.0-beta`
- Function App name: `FunctionApp20180610024421`
- Function name(s) (as appropriate): `Function1`
- Invocation ID: `577f14ae-3718-47e9-8da2-a0ea294f8708`
- Region: `Australia East`
Note log output of: `C# Timer trigger function executed at: 6/10/2018 7:35:00 AM with connection string and app setting test1`.
### Does work
- Timestamp: `2018-06-10 10:11:00.008`
- Function App version (1.0 or 2.0-beta): `2.0.11651-alpha`
- Function App name: `FunctionApp20180610024421`
- Function name(s) (as appropriate): `Function1`
- Invocation ID: `d281c04e-56ac-486c-9957-28416da1da25`
- Region: `Australia East`
Note log output of `C# Timer trigger function executed at: 6/10/2018 10:11:00 AM with connection string test2 and app setting test1`.
## Repro steps
Bind an object with an `[AppSetting(...)]` that references a connection string, e.g.:
```c#
using System;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Description;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs.Host.Config;
namespace FunctionApp1
{
public static class Function1
{
[FunctionName("Function1")]
public static void Run(
[TimerTrigger("%Schedule%")]
TimerInfo myTimer,
TraceWriter log,
[BindData]
Data data)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now} with connection string {data.ConnectionString} and app setting {data.Appsetting}");
}
}
public class Data : Attribute
{
[AppSetting(Default = "ConnectionStrings:Connection")]
public string ConnectionString { get; set; }
[AppSetting(Default = "Appsetting")]
public string Appsetting { get; set; }
}
[AttributeUsage(AttributeTargets.Parameter | AttributeTargets.ReturnValue)]
[Binding]
public class BindDataAttribute : Data { }
public class BindSessionizeReadModelSyncConfigExtension : IExtensionConfigProvider
{
public void Initialize(ExtensionConfigContext context)
{
var rule = context.AddBindingRule();
rule.BindToInput(BuildItemFromAttr);
}
private Data BuildItemFromAttr(BindDataAttribute attr)
{
return attr;
}
}
}
```
With the following settings:

## Expected behavior
The bound object should have the connection string present (e.g. `test2` in above example).
## Actual behavior
The bound object has `null` in the bound object.
## Known workarounds
Put the connection string in normal app settings (rather than connection strings) and remove the `ConnectionStrings:` prefix from the `[AppSetting(...)]` attribute.
Contributor guide
Research direction
Start with the custom BindDataAttribute, Data class, and its IExtensionConfigProvider binding rule in the repro, then compare how AppSetting resolves ordinary app settings and ConnectionStrings across the runtime versions described. Reproduce the sample and verify that the bound ConnectionString contains test2 while Appsetting still contains test1.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp
- Domain
- backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100