public static bool ProduceNewDomain(string name, object[] assemblies) { _mut.WaitOne(); sDomain?dom = null; try { foreach (object obj in assemblies) { if (obj is string) { if (((string)obj).EndsWith(".config")) { dom = new sDomain(name, (string)obj); break; } } } if (dom == null) { dom = new sDomain(name); } dom.Value.Core.LoadAssemblies(assemblies); dom.Value.Core.EstablishParent(_core); _domains.Add(dom.Value); dom.Value.Core.Startup(); _mut.ReleaseMutex(); dom.Value.Domain.DomainUnload += Domain_DomainUnload; } catch (Exception e) { if (dom.HasValue) { for (int x = 0; x < _domains.Count; x++) { if (_domains[x].Domain.FriendlyName == dom.Value.Domain.FriendlyName) { System.Error("Unloading {0} due to error in startup for application domain.", dom.Value.Domain.FriendlyName); _domains.RemoveAt(x); break; } } _mut.ReleaseMutex(); try { AppDomain.Unload(dom.Value.Domain); } catch (Exception ex) { } } dom = null; } return(dom.HasValue); }
public static bool ProduceNewDomain(string name, object[] assemblies) { _mut.WaitOne(); sDomain? dom = null; try { foreach (object obj in assemblies) { if (obj is string) { if (((string)obj).EndsWith(".config")) { dom = new sDomain(name, (string)obj); break; } } } if (dom == null) dom = new sDomain(name); dom.Value.Core.LoadAssemblies(assemblies); dom.Value.Core.EstablishParent(_core); _domains.Add(dom.Value); dom.Value.Core.Startup(); _mut.ReleaseMutex(); dom.Value.Domain.DomainUnload += Domain_DomainUnload; } catch (Exception e) { if (dom.HasValue) { for (int x = 0; x < _domains.Count; x++) { if (_domains[x].Domain.FriendlyName == dom.Value.Domain.FriendlyName) { System.Error("Unloading {0} due to error in startup for application domain.", dom.Value.Domain.FriendlyName); _domains.RemoveAt(x); break; } } _mut.ReleaseMutex(); try { AppDomain.Unload(dom.Value.Domain); } catch (Exception ex) { } } dom = null; } return dom.HasValue; }