I have an Azure Function running in Azure Portal. Its configuration resides in a configuration resource, some values are in a key vault resource. The Azure Function was implemented in .NET 6 with the in-process model. I migrated the code to .NET 8 using the isolated-worker model.
Here's my Program.cs code:
using System.Reflection;
using Azure.Identity;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace My.AzureFunctions
{
public class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWebApplication()
.ConfigureAppConfiguration(config =>
{
var builtConfig = config.Build();
var appConfigurationName = builtConfig
var defaultAzureCredentialOptions = new DefaultAzureCredentialOptions
{
ExcludeAzureCliCredential = false,
ExcludeAzurePowerShellCredential = true,
ExcludeEnvironmentCredential = false,
ExcludeManagedIdentityCredential = false,
ExcludeVisualStudioCodeCredential = true,
ExcludeVisualStudioCredential = true
};
config.AddAzureAppConfiguration(options =>
{
options.Connect(new Uri($"https://{appConfigurationName}.azconfig.io"),
new DefaultAzureCredential(defaultAzureCredentialOptions))
.ConfigureKeyVault(kvOptions =>
{
kvOptions.SetCredential(
new DefaultAzureCredential(defaultAzureCredentialOptions));
kvOptions.SetSecretRefreshInterval(TimeSpan.FromHours(1));
});
});
config.AddEnvironmentVariables();
foreach (var kvp in config.Build().AsEnumerable())
{
if (!string.IsNullOrEmpty(kvp.Value))
{
Environment.SetEnvironmentVariable(kvp.Key, kvp.Value);
}
}
})
.ConfigureServices((context, services) =>
{
// Bind configurations to options
// ...
})
.Build();
host.Run();
}
}
}
The Functions look like this:
[Function("TestTimerTrigger")]
public void TestTimerTrigger(
// This causes an error
[TimerTrigger("%TimeValue%)] TimerInfo timerInfo,
FunctionContext functionContext,
CancellationToken cancellationToken)
{
// Here TimeValue residing in Azure Configuration can be read.
_logger.LogInformation("TestTimerTrigger function executed with: {TimeValue}", _configuration["TimeValue"]);
// Also accessible here
_logger.LogInformation("TestTimerTrigger function executed with: {TimeValue}", Environment.GetEnvironmentVariable("TimeValue"));
}
[Function("MyEventTrigger")]
// The value cannot be read here, either.
public async Task Run([EventHubTrigger("", Connection = "MyEventHub:ConnectionString")] EventData[] messages,
FunctionContext functionContext)
{
// ...
}
I get these errors:
The 'TestTimerTrigger' function is in error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.TestTimerTrigger'. Microsoft.Azure.WebJobs.Host: '%TimeValue%' does not resolve to a value.
Microsoft.Azure.WebJobs.Extensions.EventHubs: EventHub account connection string with name 'MyEventHub:ConnectionString' does not exist in the settings. Make sure that it is a defined App Setting.
In the old .NET 6 in-process model Function I could access the configuration values in the Function Attributes, but after changing the code to .NET 8 and the isolated worker model, I have the described problem. The configuration itself and the way to access it has not changed. What am I doing wrong?



TimeValueis*/42 * * * * *and theMyEventHub:ConnectionStringis a valid connection string, if that's you mean.