protected override DependencyObject CreateShell() { try { var appCore = Container.GetExportedValue <IAppCoreModel>(); // Setup localtion of config files mProgramSettingsManager.AppDir = appCore.DirAppData; mProgramSettingsManager.LayoutFileName = appCore.LayoutFileName; var avLayout = Container.GetExportedValue <IAvalonDockLayoutViewModel>(); appVM = Container.GetExportedValue <IApplicationViewModel>(); var toolWindowRegistry = Container.GetExportedValue <IToolWindowRegistry>(); appVM.LoadConfigOnAppStartup(mOptions, mProgramSettingsManager, mThemes); // Attempt to load a MiniUML plugin via the model class MiniUML.Model.MiniUmlPluginLoader.LoadPlugins(appCore.AssemblyEntryLocation + @".\Plugins\MiniUML.Plugins.UmlClassDiagram\", AppViewModel); // discover via Plugin folder instead mMainWin = Container.GetExportedValue <MainWindow>(); appCore.CreateAppDataFolder(); if (mMainWin != null) { ConstructMainWindowSession(appVM, mMainWin, mProgramSettingsManager); if (mApp.AppIsShuttingDown == false) { mApp.ShutdownMode = ShutdownMode.OnLastWindowClose; } ////this.mMainWin.Show(); } else { throw new Exception("Main Window construction failed in application boot strapper class."); } } catch (Exception exp) { logger.Error(exp); try { // Cannot set shutdown mode when application is already shuttong down if (mApp.AppIsShuttingDown == false) { mApp.ShutdownMode = ShutdownMode.OnExplicitShutdown; } } catch (Exception exp1) { logger.Error(exp1); } try { // 1) Application hangs when this is set to null while MainWindow is visible // 2) Application throws exception when this is set as owner of window when it // was never visible. // if (Application.Current.MainWindow != null) { if (Application.Current.MainWindow.IsVisible == false) { Application.Current.MainWindow = null; } } } catch (Exception exp2) { logger.Error(exp2); } _MsgBox.Show(exp, Strings.STR_MSG_ERROR_FINDING_RESOURCE , MsgBoxButtons.OKCopy, MsgBoxImage.Error); if (mApp.AppIsShuttingDown == false) { mApp.Shutdown(); } } return(mMainWin); }