azure-webjobs-sdk
azure-webjobs-sdk copied to clipboard
StackOverFlow Exception from WebJobsBuilderExtensions while running Azure function locally
I have written Azure function which is throwing StackOverFlow Exception in the below code from class WebJobsBuilderExtensions in the namespace ` Microsoft.Azure.WebJobs
services.TryAddEnumerable(ServiceDescriptor.Singleton<IHostedService, JobHostService>());
Here is my Startup.cs class
` [assembly: WebJobsStartup(typeof(Startup))]
namespace FuncApp
{
public class Startup : IWebJobsStartup
{
public void Configure(IWebJobsBuilder builder)
{
var config = new ConfigurationBuilder()
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
builder.Services
.AddSingleton<IConfiguration>(config)
.AddSingleton(serviceProvider => serviceProvider)
.AddLogging();
}
}
} `
Repro steps
Reproduction steps
- Create an azure trigger function using Visual studio 2019 or 2022
- Add Startup class and add above code
- Run
Expected behavior
Azure function shall run without any exceptions
Actual behavior
Stackoverflow exception
Known workarounds
@codemaker We are able to reproduce the issue and getting the stack overflow exception, we will check with our next level team and update you with the solution. you can share us the function app name as below so that we check the system logs and reason for the exception. Sharing Your Function App name privately
@ramya894 We did not deploy the function to the cloud and hence there will be no app name to share.
@codemaker What happens when you comment out/remove .AddSingleton(serviceProvider => serviceProvider)
?
@kshyju It works fine when we remove .AddSingleton(serviceProvider => serviceProvider)
, So don't we need this line anymore? How did it was working before ?
Yes, that line is causing your issue. You should not use that.
BTW, the other code snippet you have where you are replacing the Configuration is a problematic approach. If you want to add another JSON file as configuration source, the recommended approach is to inherit FunctionsStartup
and override the ConfigureAppConfiguration
method as shown in this doc.
Closing as answered.