public void Teardown()
        {
            try
            {
                if (_runner != null)
                {
                    _runner.Dispose();
                }
            }
            catch (Exception)
            {
            }

            _runner = null;
            if (_domain != null)
            {
                AppDomain.Unload(_domain);
                _domain = null;
            }
        }
        private ApplicationStartResponse createAppDomain(ApplicationSettings settings)
        {
            var setup = new AppDomainSetup
            {
                ApplicationName   = "FubuMVC-Kayak-" + settings.Name + "-" + Guid.NewGuid(),
                ConfigurationFile = "Web.config",
                ShadowCopyFiles   = "true",
                PrivateBinPath    = "bin",
                ApplicationBase   = settings.PhysicalPath
            };

            copyAssembly("FubuKayak", setup);
            copyAssembly <ApplicationRunner>(setup);
            copyAssembly <FubuOwinHost>(setup);
            copyAssembly("Kayak", setup);
            copyAssembly("Gate", setup);
            copyAssembly("Gate.Helpers", setup);
            copyAssembly("Gate.Kayak", setup);

            Console.WriteLine("Starting a new AppDomain at " + setup.ApplicationBase);

            _domain = AppDomain.CreateDomain(setup.ApplicationName, null, setup);

            Type proxyType = typeof(ApplicationRunner);

            _runner =
                (ApplicationRunner)
                _domain.CreateInstanceAndUnwrap(proxyType.Assembly.FullName, proxyType.FullName);

            var resetEvent = new ManualResetEvent(false);
            var response   = _runner.StartApplication(settings, resetEvent);

            if (response.Status == ApplicationStartStatus.Started)
            {
                setupWatchers(settings, response);
            }

            return(response);
        }