Stackoverflow error comes when adding serviceProvider

DEEPAK KUMPALA 191 Reputation points
2023-02-20T05:39:37.7866667+00:00

I had Azure function which was written using .NET Core 3.1 and suddenly stopped working and showing StackOverflow exception in below code at TryAddEnumerables

User's image

Here is my code

builder.Services
            .AddSingleton<IConfiguration>(config)
            .AddSingleton(serviceProvider => serviceProvider)
            .AddLogging()
            .AddSingleton<IManager, CManager>()
            .AddSingleton<IRegexManager, RegexManager>()

When I comment the below line, StackOverflow error resolved BUT application does to work as expected.

 .AddSingleton(serviceProvider => serviceProvider)

Here is stack trace

User's image

What might be the root cause? I have posted the same question here: https://stackoverflow.com/questions/75491471/stackoverflow-error-comes-in-microsoft-extensions-hosting-class

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,131 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,029 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.