title: An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll
body: <p>In my Asp.net MVC project</p>
  
  <p>I have a bootsrapper that initialize a unity-container.</p>
  
  <p>I don't know why, but I get </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.StackOverflowException' occurred in System.Core.dll</p>
  </blockquote>
  
  <p>I have doubled checked and registration is done only in my initializer.</p>
  
  <p>All dependencies are injected in the ctors only.</p>
  
  <p>What could have caused this?</p>
  
  <pre><code>    protected void Application_Start()
      {
          AreaRegistration.RegisterAllAreas();
          WebApiConfig.Register(GlobalConfiguration.Configuration);
          FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
          RouteConfig.RegisterRoutes(RouteTable.Routes);
  
          Initializer.Initialize();
          BundleConfig.RegisterBundles(BundleTable.Bundles);
      }
  </code></pre>
  
  <p>It fails after <code>BundleConfig.RegisterBundles(BundleTable.Bundles);</code></p>
  
  <pre><code>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&lt;ISettingsManager, SettingsManager&gt;();
  
              container.RegisterType&lt;IMamDataManager, MamDataManager&gt;();
  
              container.RegisterType&lt;IAppsDataManager, AppsDataManager&gt;();
              #endregion
  
              #region Dals
              container.RegisterType&lt;IDal&lt;ClientService.DAL.EntityFramework.App&gt;, AppsDal&gt;();
  
              #endregion Dals
  
              #region cache
              container.RegisterType&lt;ICache&lt;string, ClientService.DAL.EntityFramework.Group&gt;, GroupsCache&gt;(new ContainerControlledLifetimeManager());
  
              container.RegisterType&lt;ICache&lt;string, ClientService.DAL.EntityFramework.App&gt;, AppsCache&gt;(new ContainerControlledLifetimeManager());
  
              container.RegisterType&lt;ICache&lt;string, SettingsServiceData&gt;, SettingsServiceDataCache&gt;(new ContainerControlledLifetimeManager());
              #endregion cache
  
              #region Pollers
              container.RegisterType&lt;IPoller&lt;ClientService.DAL.EntityFramework.Group&gt;, GroupsPoller&gt;(new ContainerControlledLifetimeManager());
  
              container.RegisterType&lt;IPoller&lt;ClientService.DAL.EntityFramework.App&gt;, AppsPoller&gt;(new ContainerControlledLifetimeManager());
  
              container.RegisterType&lt;IPoller&lt;SettingsServiceData&gt;, SettingsPoller&gt;(new ContainerControlledLifetimeManager());
  
  
  
              #endregion Pollers
  
  
              container.RegisterType&lt;IDefaultConfigurationGroupSingleton, DefaultConfigurationGroupSingleton&gt;(new ContainerControlledLifetimeManager());
  
              container.RegisterType&lt;IApplicationLogger, Log4NetLogger&gt;();
  
              if (!isInitialize)
              {
                  isInitialize = true;
              }
          }
      }
  }
  </code></pre>