diff --git a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs index 693199dd76f..3dd0aa76c50 100644 --- a/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs +++ b/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.OSX.cs @@ -127,6 +127,7 @@ namespace System.IO { Debug.Assert(_eventStream == IntPtr.Zero); Debug.Assert(_watcherRunLoop == IntPtr.Zero); + Debug.Assert(_callback == null); // Make sure we only do this if there is a valid directory if (String.IsNullOrEmpty(_directory) == false) @@ -191,6 +192,12 @@ namespace System.IO Interop.CoreFoundation.CFRelease(_eventStream); _eventStream = IntPtr.Zero; } + + // Cleanup the callback + if (_callback != null) + { + _callback = null; + } } private void RestartStream()