/// <exclude />
        public static void CompileAll()
        {
            FieldInfo theBuildManagerFieldInfo = typeof(System.Web.Compilation.BuildManager).GetField("_theBuildManager", BindingFlags.NonPublic | BindingFlags.Static);
            FieldInfo cachesManagerFieldInfo   = typeof(System.Web.Compilation.BuildManager).GetField("_caches", BindingFlags.NonPublic | BindingFlags.Instance);

            object      currentBuilderManager = theBuildManagerFieldInfo.GetValue(null);
            IEnumerable caches = cachesManagerFieldInfo.GetValue(currentBuilderManager) as IEnumerable;

            Type      standardDiskBuildResultCacheType = caches.OfType <object>().Where(f => f.GetType().FullName == "System.Web.Compilation.StandardDiskBuildResultCache").Select(f => f.GetType()).Single();
            FieldInfo maxRecompilationsFieldInfo       = standardDiskBuildResultCacheType.BaseType.GetField("s_maxRecompilations", BindingFlags.NonPublic | BindingFlags.Static);

            object oldValue = maxRecompilationsFieldInfo.GetValue(null);

            maxRecompilationsFieldInfo.SetValue(null, 500);

            IEnumerable <string> paths = GetControlPaths();

            IPerformanceCounterToken performanceCounterToken = PerformanceCounterFacade.BeginAspNetControlCompile();

            // ParallelFacade.ForEach(paths, path => // Call to parallelization facade causes a deadlock while starting-up!!!
            foreach (string path in paths)
            {
                int  t1   = Environment.TickCount;
                Type type = BuildManagerHelper.GetCompiledType(path);
                int  t2   = Environment.TickCount;

                LoggingService.LogVerbose("RGB(180, 180, 255)ControlCompilerService", string.Format("{0} compiled in {1} ms", path, t2 - t1));
            }

            PerformanceCounterFacade.EndAspNetControlCompile(performanceCounterToken, paths.Count());

            // maxRecompilationsFieldInfo.SetValue(null, oldValue);
        }
 /// <summary>
 /// Gets a user control. Prevents an exception that appears in Visual Studio while debugging
 /// </summary>
 /// <param name="virtualPath"></param>
 /// <returns></returns>
 public static Type GetCompiledType(string virtualPath)
 {
     using (BuildManagerHelper.DisableUrlMetadataCachingScope())
     {
         return(System.Web.Compilation.BuildManager.GetCompiledType(virtualPath));
     }
 }
        private static void LoadAllControls()
        {
            try
            {
                const string configFileFilePath = "~/App_Data/Composite/Composite.config";
                var          config             = XDocument.Load(PathUtil.Resolve(configFileFilePath));

                var controlPathes = (from element in config.Descendants()
                                     let userControlVirtualPath = (string)element.Attribute("userControlVirtualPath")
                                                                  where userControlVirtualPath != null
                                                                  select userControlVirtualPath).ToList();

                var stopWatch = new Stopwatch();
                stopWatch.Start();

                Log.LogVerbose(LogTitle, "Preloading all the controls, starting");

                foreach (var controlPath in controlPathes)
                {
                    if (!C1File.Exists(PathUtil.Resolve(controlPath)))
                    {
                        Log.LogWarning(LogTitle, "Missing a control file '{0}' referenced in '{1}'", controlPath, configFileFilePath);
                        continue;
                    }

                    try
                    {
                        BuildManagerHelper.GetCompiledType(controlPath);
                    }
                    catch (ThreadAbortException)
                    {
                        // this exception is automatically rethrown after this catch
                    }
                    catch (Exception ex)
                    {
                        Log.LogWarning(LogTitle, ex);
                    }
                }

                stopWatch.Stop();

                Log.LogVerbose(LogTitle, "Preloading all the controls: " + stopWatch.ElapsedMilliseconds + "ms");

                Func <string, bool> isAshxAsmxPath = f => f == ".ashx" || f == ".asmx";
                Func <string, bool> isAspNetPath   = f => f == ".aspx" || isAshxAsmxPath(f);
                var aspnetPaths = DirectoryUtils.GetFilesRecursively(PathUtil.Resolve("~/Composite")).Where(f => isAshxAsmxPath(Path.GetExtension(f)))
                                  .Concat(DirectoryUtils.GetFilesRecursively(PathUtil.Resolve("~/Renderers")).Where(f => isAspNetPath(Path.GetExtension(f))))
                                  .ToList();

                stopWatch.Reset();
                stopWatch.Start();

                foreach (var aspnetPath in aspnetPaths)
                {
                    try
                    {
                        BuildManagerHelper.GetCompiledType(PathUtil.GetWebsitePath(aspnetPath));
                    }
                    catch (ThreadAbortException)
                    {
                        // this exception is automatically rethrown after this catch
                    }
                    catch (Exception ex)
                    {
                        Log.LogWarning("BuildManagerHelper", ex);
                    }
                }

                stopWatch.Stop();

                Log.LogVerbose(LogTitle, "Preloading all asp.net files: " + stopWatch.ElapsedMilliseconds + "ms");
            }
            catch (ThreadAbortException)
            {
            }
            catch (Exception ex)
            {
                Log.LogWarning(LogTitle, ex);
            }
        }