var host = new HostBuilder()
.ConfigureAppConfiguration((host, builder) =>
{
builder
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{host.HostingEnvironment.EnvironmentName}.json", true, true);
}).Build().Run();
Above is a portion of the code in my V4 Azure Function's Program.cs which runs on .NET 7.0
In my Azure Function, I use the %configurationName% convention to trigger this timer function every minute.
[Function(nameof(FunctionATrigger))]
public async Task Run(
[TimerTrigger("%Values:TimerTriggerPeriod%", RunOnStartup = false)] TimerInfo timerInfo)
{
}
However, I keep getting the error:
[2023-03-16T17:44:37.042Z] The 'FunctionATrigger' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.FunctionATrigger'. Microsoft.Azure.WebJobs.Host: '%Values:TimerTriggerPeriod%' does not resolve to a value.
I confirmed my host.HostingEnvironment.EnvironmentName is 'local'
In my appsettings.local.json I have:
{
"Values": {
"TimerTriggerPeriod": "0 * * * * *"
}
}
I also tried %TimerTriggerPeriod% with the following appsetting without sucess :
{
"TimerTriggerPeriod": "0 * * * * *"
}
Could this be something in .NET 7 and Azure Function V4?
As a test I verified I can access this value via Dependency Injection of IConfiguration
_configuration["Values:TimerTriggerPeriod"]
Make sure you are loading appsettings.local.json. In order to verify you can add the config section to your secrets file or add them to appsettings.json.The following works for me:
[Function(nameof(FunctionATrigger))]
public async Task Run(
[TimerTrigger("%MyFunctionName:DailyCronMidnightPST%"
#if !RELEASE
, RunOnStartup = true
#endif
)] TimerInfo myTimer, ILogger log)
{
}
appsettings.local.json:
{
"MyFunctionName": {
"4HourCronStartAt1AMPST": "0 0 8/4 * * *",
"DailyCronMidnightPST": "0 0 7 * * *",
"Throughput": 10000,
"BatchSize": 100
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With