Exemplo n.º 1
0
		public static IDisposable Register(string assemblyPath, AppDomain domain = null)
		{
			if (domain == null)
				domain = AppDomain.CurrentDomain;
			var resolver = new AssemblyResolver { AssemblyPath = assemblyPath, AppDomain = domain };
			domain.AssemblyResolve += resolver.Resolve;
			return resolver;
		}
Exemplo n.º 2
0
		public static IDisposable Register(IEnumerable<string> files, AppDomain domain = null)
		{
			if (files == null)
				return null;
			if (domain == null)
				domain = AppDomain.CurrentDomain;
			var resolver = new AssemblyResolver { AppDomain = domain, Files = files.ToList() };
			domain.AssemblyResolve += resolver.Resolve;
			return resolver;
		}
Exemplo n.º 3
0
        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);
        }