bool SetupAppDomain(bool setBuilder) { if (!requiresNewDomain && domain != null) { EnsureWatcher(); return(false); } requiresNewDomain = false; #pragma warning disable 618 // doesn't work without for some reason, and there's no non-obsolete alternative. if (!AppDomain.CurrentDomain.ShadowCopyFiles) { AppDomain.CurrentDomain.SetShadowCopyFiles(); } #pragma warning restore 618 var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var initializeAssembly = Builders.BaseCompiledInterfaceBuilder.InitializeAssembly; var shadowCopyDirs = string.Join(";", GetShadowCopyDirs().Distinct()); var setup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, PrivateBinPath = $"{baseDir};{shadowCopyDirs}", ShadowCopyFiles = "true", ShadowCopyDirectories = shadowCopyDirs, CachePath = Path.Combine(Path.GetDirectoryName(MainAssembly), "Eto.Designer"), LoaderOptimization = LoaderOptimization.MultiDomain, //LoaderOptimization = LoaderOptimization.NotSpecified }; proxy = null; domain = AppDomain.CreateDomain("eto.designer." + domainCount++, null, setup); try { using (AssemblyResolver.Register(baseDir)) { var proxyObject = domain.CreateInstanceFromAndUnwrap(typeof(AppDomainProxy).Assembly.Location, typeof(AppDomainProxy).FullName) as AppDomainProxy; proxy = proxyObject as AppDomainProxy; if (proxy == null) { throw new InvalidOperationException($"Could not create proxy for domain\nApplicationBase: {AppDomain.CurrentDomain.BaseDirectory}\nBaseDir: {baseDir}\nShadowCopyDirs: {shadowCopyDirs}"); } } proxy.Init(Platform.Instance.GetType().AssemblyQualifiedName, initializeAssembly, MainAssembly, references); proxy.HookupEvents(eventSink); if (setBuilder) { proxy.SetBuilder(fileName); } if (!string.IsNullOrEmpty(code)) { proxy.Update(code); } } catch (Exception ex) { UnloadDomain(domain); domain = null; proxy = null; throw new InvalidOperationException($"Could not set up proxy for domain: {ex.GetBaseException().Message}", ex); } EnsureWatcher(); return(true); }
public bool SetBuilder(string fileName) { this.fileName = fileName; SetupAppDomain(false); return(proxy.SetBuilder(fileName)); }
bool SetupAppDomain(bool setBuilder) { if (!requiresNewDomain && domain != null) return false; requiresNewDomain = false; #pragma warning disable 618 // doesn't work without for some reason, and there's no non-obsolete alternative. if (!AppDomain.CurrentDomain.ShadowCopyFiles) AppDomain.CurrentDomain.SetShadowCopyFiles(); #pragma warning restore 618 var baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var initializeAssembly = Builders.BaseCompiledInterfaceBuilder.InitializeAssembly; var shadowCopyDirs = string.Join(";", GetShadowCopyDirs().Distinct()); var setup = new AppDomainSetup { ApplicationBase = AppDomain.CurrentDomain.BaseDirectory, PrivateBinPath = $"{baseDir};{shadowCopyDirs}", ShadowCopyFiles = "true", ShadowCopyDirectories = shadowCopyDirs, CachePath = Path.Combine(Path.GetDirectoryName(MainAssembly), "Eto.Designer"), LoaderOptimization = LoaderOptimization.MultiDomain, //LoaderOptimization = LoaderOptimization.NotSpecified }; proxy = null; domain = AppDomain.CreateDomain("eto.designer." + domainCount++, null, setup); try { using (AssemblyResolver.Register(baseDir)) { var proxyObject = domain.CreateInstanceFromAndUnwrap(typeof(AppDomainProxy).Assembly.Location, typeof(AppDomainProxy).FullName) as AppDomainProxy; proxy = proxyObject as AppDomainProxy; if (proxy == null) throw new InvalidOperationException($"Could not create proxy for domain\nApplicationBase: {AppDomain.CurrentDomain.BaseDirectory}\nBaseDir: {baseDir}\nShadowCopyDirs: {shadowCopyDirs}"); } proxy.Init(Platform.Instance.GetType().AssemblyQualifiedName, initializeAssembly, MainAssembly, references); domain.DomainUnload += Domain_DomainUnload; proxy.ControlCreated = eventSink.ControlCreated; proxy.Error = eventSink.Error; if (setBuilder) proxy.SetBuilder(fileName); if (!string.IsNullOrEmpty(code)) proxy.Update(code); } catch (Exception ex) { UnloadDomain(domain); domain = null; proxy = null; throw new InvalidOperationException($"Could not set up proxy for domain: {ex.GetBaseException().Message}", ex); } if (watcher == null && !string.IsNullOrEmpty(MainAssembly)) { watcher = new FileSystemWatcher(Path.GetDirectoryName(MainAssembly), "*.dll"); watcher.Changed += (sender, e) => Application.Instance.AsyncInvoke(() => timer.Start()); watcher.Created += (sender, e) => Application.Instance.AsyncInvoke(() => timer.Start()); watcher.EnableRaisingEvents = true; } return true; }