I'm getting a stack overflow exception after I load 4 or 5 times a simple controller action. The web app is running on Azure and I was able to dump the exception information and the problem seems to be related to Dependency Injection.
internal object GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope) { if (_disposed) { ThrowHelper.ThrowObjectDisposedException(); --> this is executed } var realizedService = RealizedServices.GetOrAdd(serviceType, _createServiceAccessor); _callback?.OnResolve(serviceType, serviceProviderEngineScope); return realizedService.Invoke(serviceProviderEngineScope); } Running the web app in my computer has no issues, it only fails in PROD.
This is how I captured the exception in Azure: https://blogs.msdn.microsoft.com/benjaminperkins/2017/06/28/capture-a-stackoverflowexception-and-make-a-dump-0xc00000fd/
I opened the dump in Visual Studio and I could identify the code line where it failed (described above) but I still don't know how to fix it. All my dependencies are resolved with 'scope' lifetime.
Any help is appreciated.
services.AddHttpClient<Client>().AddHttpMessageHandler<Handler>();. In this case, DI container didn't warn me about cyclic dependency as it usually do.