public void Initialize() { if (Instance != null) { FormUI?.BringToFront(); WindowUI?.Activate(); return; } try { AppDomain.CurrentDomain.AssemblyResolve += _assemblyResolver; if (Type != null) { if (!typeof(IModule).IsAssignableFrom(Type)) { object instance = Activator.CreateInstance(Type); WindowUI = (instance as Window); if (WindowUI != null) { Instance = (IModule)WindowUI.DataContext; } } else { Instance = (IModule)FormatterServices.GetUninitializedObject(Type); } } else { Instance = new DummyModule(this); } Instance.Installer = App.Master; if (Type != null && WindowUI == null) { ConstructorInfo moduleConstructor = Type.GetConstructor(Type.EmptyTypes); moduleConstructor.Invoke(Instance, null); } if (App.Master.Connection.IsConnected) { Instance.Synchronize(App.Master.Game); Instance.Synchronize(App.Master.GameData); } FormUI = (Instance as Form); if (FormUI != null) { FormUI.Show(); FormUI.FormClosed += UserInterface_Closed; } else if (WindowUI != null) { WindowUI.Show(); WindowUI.Closed += UserInterface_Closed; } } catch { Dispose(); } finally { if (Instance != null) { CurrentState = INITIALIZED_STATE; } AppDomain.CurrentDomain.AssemblyResolve -= _assemblyResolver; } }