An unhandled exception of type ‘System.StackOverflowException’ occurred in System.Core.dll

In my Asp.net MVC project

I have a bootsrapper that initialize a unity-container.

I don’t know why, but I get

An unhandled exception of type ‘System.StackOverflowException’ occurred in System.Core.dll

I have doubled checked and registration is done only in my initializer.

All dependencies are injected in the ctors only.

What could have caused this?

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);

        Initializer.Initialize();
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    }

It fails after BundleConfig.RegisterBundles(BundleTable.Bundles);

public static class Initializer
{
    private static bool isInitialize;
    private static readonly object LockObj = new object();
    private static IUnityContainer defaultContainer = new UnityContainer();

    static Initializer()
    {
        Initialize();
    }

    public static void Initialize()
    {
        if (isInitialize)
            return;

        lock (LockObj)
        {
            IUnityContainer container = defaultContainer;

            //registering Unity for MVC
            DependencyResolver.SetResolver(new UnityDependencyResolver(container));

            //registering Unity for web API
            //  GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);

            #region managers
            container.RegisterType<ISettingsManager, SettingsManager>();

            container.RegisterType<IMamDataManager, MamDataManager>();

            container.RegisterType<IAppsDataManager, AppsDataManager>();
            #endregion

            #region Dals
            container.RegisterType<IDal<ClientService.DAL.EntityFramework.App>, AppsDal>();

            #endregion Dals

            #region cache
            container.RegisterType<ICache<string, ClientService.DAL.EntityFramework.Group>, GroupsCache>(new ContainerControlledLifetimeManager());

            container.RegisterType<ICache<string, ClientService.DAL.EntityFramework.App>, AppsCache>(new ContainerControlledLifetimeManager());

            container.RegisterType<ICache<string, SettingsServiceData>, SettingsServiceDataCache>(new ContainerControlledLifetimeManager());
            #endregion cache

            #region Pollers
            container.RegisterType<IPoller<ClientService.DAL.EntityFramework.Group>, GroupsPoller>(new ContainerControlledLifetimeManager());

            container.RegisterType<IPoller<ClientService.DAL.EntityFramework.App>, AppsPoller>(new ContainerControlledLifetimeManager());

            container.RegisterType<IPoller<SettingsServiceData>, SettingsPoller>(new ContainerControlledLifetimeManager());



            #endregion Pollers


            container.RegisterType<IDefaultConfigurationGroupSingleton, DefaultConfigurationGroupSingleton>(new ContainerControlledLifetimeManager());

            container.RegisterType<IApplicationLogger, Log4NetLogger>();

            if (!isInitialize)
            {
                isInitialize = true;
            }
        }
    }
}

An unhandled exception of type ‘System.StackOverflowException’ occurred

I am getting the error An unhandled exception of type ‘System.StackOverflowException’ occurred in Forte Sender.exe in my code. I have the understanding that this means there is an infinite loop in my

An unhandled exception of type ‘System.NullReferenceException’ occurred

I’m trying to put to array my SQL query string but I encounter this error An unhandled exception of type ‘System.NullReferenceException’ occurred What is the possible problem I have? Dim myList A

An unhandled exception of type ‘System.StackOverflowException’ occurred in Unknown Module

I am regularly encountering errors of type An unhandled exception of type ‘System.StackOverflowException’ occurred in Unknown Module.. This happens in a website with a quite large code base. But the

An unhandled exception of type ‘System.TypeInitializationException’ occurred in EntityFramework.dll

I was trying to learn entity framework and sqlite using this tutorial. However, I get an error. Error thrown is: An unhandled exception of type ‘System.TypeInitializationException’ occurred in EntityF

An unhandled exception of type ‘System.UnauthorizedAccessException’ occurred in mscorlib.dll

I’m trying to create a simple windows-explorer like treeview in c#, however I am getting this error at runtime: An unhandled exception of type ‘System.UnauthorizedAccessException’ occurred in mscorli

Error in VB: An unhandled exception of type ‘System.IndexOutOfRangeException’ occurred in language.exe

An unhandled exception of type ‘System.IndexOutOfRangeException’ occurred in language.exe Additional information: Index was outside the bounds of the array. here is the code where the error is: Privat

An unhandled exception of type ‘System.ServiceModel.CommunicationException’ occurred in mscorlib.dll

I am getting the following error when calling a method in a webservice, not developed by me. An unhandled exception of type ‘System.ServiceModel.CommunicationException’ occurred in mscorlib.dll I need

An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in mscorlib.dll

In the following code, I got following error. An unhandled exception of type ‘System.ArgumentOutOfRangeException’ occurred in mscorlib.dll Additional information: Index was out of range. Must be non-

Redis .StoreAll An unhandled exception of type ‘System.StackOverflowException’ occurred in mscorlib.dll

I´m using Redis, but the StoreAll doesn´t work. An unhandled exception of type ‘System.StackOverflowException’ occurred in mscorlib.dll var newOrders = (from i in DB.Produtoes.OrderByDescending(d =&

An unhandled exception of type ‘System.IO.FileNotFoundException’ occurred in Unknown Module

I am developing a c# application and I get the following error at debug runtime: An unhandled exception of type ‘System.IO.FileNotFoundException’ occurred in Unknown Module. Additional information: C

Answers

Without providing code, I guess this is due to a circular dependency. Another possible reason is that you have an improper loop in one of your constructors.

As an example, A class requires an instance of B to be resolved; B class requires an instance of C class to be resolved and C class needs an instance of A to be resolved. This results in an infinite loop:

public class A
{
    public A(B b)
    {
    }
}

public class B
{
    public B(C c)
    {
    }
}

public class C
{
    public B(A a)
    {
    }
}