private static void UpdateAssemblyWatchers() { string[] assemblyPaths = SharedRuntimeState.GetHotReloadAssemblyPaths(); if (assemblyPaths != null) { HashSet <string> newAssemblyPaths = new HashSet <string>(); HashSet <string> removedAssemblyPaths = new HashSet <string>(); foreach (string assemblyPath in assemblyWatchers.Keys) { if (!assemblyPaths.Contains(assemblyPath)) { removedAssemblyPaths.Add(assemblyPath); } } foreach (string assemblyPath in assemblyPaths) { if (!assemblyWatchers.ContainsKey(assemblyPath)) { newAssemblyPaths.Add(assemblyPath); } } foreach (string assemblyPath in removedAssemblyPaths) { assemblyWatchers[assemblyPath].Dispose(); assemblyWatchers.Remove(assemblyPath); } foreach (string assemblyPath in newAssemblyPaths) { if (Directory.Exists(Path.GetDirectoryName(assemblyPath))) { FileSystemWatcher assemblyWatcher = new FileSystemWatcher(); assemblyWatcher.Path = Path.GetDirectoryName(assemblyPath); assemblyWatcher.Filter = Path.GetFileName(assemblyPath); assemblyWatcher.NotifyFilter = NotifyFilters.LastWrite;//NotifyFilters.CreationTime; assemblyWatcher.EnableRaisingEvents = true; assemblyWatcher.Changed += AssemblyWatcher_Changed; assemblyWatchers.Add(assemblyPath, assemblyWatcher); } } } if (assemblyWatchers.Count == 0) { SharedRuntimeState.LogWarning("No assembly watchers active for hotreload (\"USharpRuntime reload\" command can be used instead)"); } }
private static void UpdateAssemblyWatchers() { string platformName = SharedRuntimeState.GetPlatformName(); if (SharedRuntimeState.CurrentRuntime == EDotNetRuntime.Mono && !string.IsNullOrEmpty(platformName) && platformName.ToLower() == "mac") { // libmono-native-compat.dylib (required by FileSystemWatcher) either doesn't load or is corrupted? // It crashes the Mono runtime when doing a symbol lookup (not sure which symbol) // // abort_with_payload // dyld::fastBindLazySymbol(ImageLoader**, unsigned long) // dyld_stub_binder // ---- managed frames ---- // mono_jit_runtime_invoke return; } string[] assemblyPaths = SharedRuntimeState.GetHotReloadAssemblyPaths(); if (assemblyPaths != null) { HashSet<string> newAssemblyPaths = new HashSet<string>(); HashSet<string> removedAssemblyPaths = new HashSet<string>(); foreach (string assemblyPath in assemblyWatchers.Keys) { if (!assemblyPaths.Contains(assemblyPath)) { removedAssemblyPaths.Add(assemblyPath); } } foreach (string assemblyPath in assemblyPaths) { if (!assemblyWatchers.ContainsKey(assemblyPath)) { newAssemblyPaths.Add(assemblyPath); } } foreach (string assemblyPath in removedAssemblyPaths) { assemblyWatchers[assemblyPath].Dispose(); assemblyWatchers.Remove(assemblyPath); } foreach (string assemblyPath in newAssemblyPaths) { if (Directory.Exists(Path.GetDirectoryName(assemblyPath))) { FileSystemWatcher assemblyWatcher = new FileSystemWatcher(); assemblyWatcher.Path = Path.GetDirectoryName(assemblyPath); assemblyWatcher.Filter = Path.GetFileName(assemblyPath); assemblyWatcher.NotifyFilter = NotifyFilters.LastWrite;//NotifyFilters.CreationTime; assemblyWatcher.EnableRaisingEvents = true; assemblyWatcher.Changed += AssemblyWatcher_Changed; assemblyWatchers.Add(assemblyPath, assemblyWatcher); } } } if (assemblyWatchers.Count == 0) { SharedRuntimeState.LogWarning("No assembly watchers active for hotreload (\"USharpRuntime reload\" command can be used instead)"); } }