I have an Azure Function project built on NET6. Function runtime version: 4.x, and this is my host.json
{
"version": "2.0",
"functions": [ "MyFunction" ],
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true
}
}
},
"extensions": {
"queues": {
"batchSize": 1,
"newBatchThreshold": 0,
"maxDequeueCount": 5,
"visibilityTimeout": "00:01:00"
}
}
}
But when I run in localhost for debugging, it looks like the host is not used at all:
- All the functions run instead of the one specified in the “functions” field in the host
- I force an exception in my queue trigger function but message get visible again after 10 minutes instead of 1 minute as specified in the extensions>queues>visibilityTimeout property
I checked in the bin folder (bin>Debug>net6.0) and I found the correct host.json.
I tried to create another project from scratch (same configuration) and I have the same problem.
Specifying that I’m not running on an isolated worker model
I don’t know if it may conflict, but I want to specify that I have configured dependency injection as well, in the Startup.cs class.
I tried to configure visibilityTimeout in my Startup class as well, but again, it hasn’t worked.
I don’t have any other idea
2
I realized that there was a conflict caused by my Startup class. I was creating an IConfiguration as singleton, but it looks like that it overrides another IConfiguration singleton that is initialized by the framework with host.json settings.
I found the solution in the following answer: /a/60160493/8875147
Basically, in the answer, he suggests to check if another IConfiguration is already present, if yes, those settings are added to the new IConfiguration to combine both of them
public IConfigurationRoot AddSettings(IServiceCollection services, string basePath, string name, bool optional, bool reloadOnChange)
{
var builder = new ConfigurationBuilder().SetBasePath(basePath);
// check if an IConfiguration has already been registered
var existingConfig = builder.Services.FirstOrDefault(x => x.ServiceType.Name == nameof(IConfiguration));
if(existingConfig != null)
{
// get an instance of it and include it in the new config builder
var sp = builder.Services.BuildServiceProvider();
var existingInstance = sp.GetService<IConfiguration>();
builder.AddConfiguration(existingInstance);
}
// Register/load the requested json settings file
builder.AddJsonFile(name, optional, reloadOnChange);
// Add all environment vars and build the ConfigurationRoot object. Then register it with the services container
builder.AddEnvironmentVariables();
var config = builder.Build();
// Register the resulting IConfigurationRoot to as a singleton
services.AddSingleton<IConfiguration>(config);
return config;
}