You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
FileSystemWatcher doesn't trigger Deleted event for file when watched directory is deleted on OSX #44484
Create a FileSystemWatcher that watches a directory.
Create a file in that directory and observe Created event.
Delete the file and observe Deleted event.
Create another file in that directory and observe Created event.
Delete the directory, and no deleted event ever arrives.
Configuration
Which version of .NET is the code running on? .NET 5.0
What OS and version, and what distro if applicable? OSX 10.13.6
What is the architecture (x64, x86, ARM, ARM64)? x64
Do you know whether it is specific to that configuration? It appears to be specific to OSX
Regression?
Not a regression, but different than other platforms
Other information
May be similar to #30415
Discovered when working on #41426
This appears to be unique to only when the root-level watched directory is removed. If a directory underneath the root directory is removed then the deleted event is observed. I've updated the sample above to better illustrate this.
Not a regression, but different than other platforms
@ericstj the sample you provided behaves similar to what you describe on Windows and Linux, is there something that I am missing?
This is the output that I get:
Created C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\sub\4fo3tpfq.nwd
Deleted C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\sub\4fo3tpfq.nwd
Created C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\sub\pboshy2t.kar
Deleted C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\sub\pboshy2t.kar
Deleted C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\sub
Created C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\k2lg0a3p.kyq
Deleted C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\k2lg0a3p.kyq
Created C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\2mjivqn4.qf5
Deleted C:\Users\dacantu\AppData\Local\Temp\rr05f1lh.mdy\2mjivqn4.qf5
False
I see now, it is reporting Create twice and not reporting Delete when you erase the root as you mentioned:
Created /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/sub/noozqidc.ibi
Created /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/sub/noozqidc.ibi
Deleted /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/sub/noozqidc.ibi
Created /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/sub/ibmlfqwy.nie
Created /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/sub/ibmlfqwy.nie
Deleted /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/sub/ibmlfqwy.nie
Created /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/sub
Deleted /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/sub
Created /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/xbdmmr50.et3
Created /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/xbdmmr50.et3
Deleted /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/xbdmmr50.et3
Created /var/folders/gz/6z3dn8kn20g5wlk7rt7cs0h40000gq/T/xltqrcpx.vdv/xxfnco43.dmg
False
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.
Activity
ericstj commentedon Nov 10, 2020
This appears to be unique to only when the root-level watched directory is removed. If a directory underneath the root directory is removed then the deleted event is observed. I've updated the sample above to better illustrate this.
carlossanlop commentedon Nov 14, 2020
It was my understanding that
FileSystemWatcherdoes not watch changes in the monitored directory itself, only on the files and directories inside it.I remembered that fact from this closed issue, from which I learned that not even Windows reports events from the monitored directory itself. That is how the behavior is described in the Windows API we invoke: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-readdirectorychangesw
jozkee commentedon Nov 14, 2020
@ericstj the sample you provided behaves similar to what you describe on Windows and Linux, is there something that I am missing?
This is the output that I get:
ericstj commentedon Nov 14, 2020
This failure is specific to Mac (OSX) which uses a different implementation. On Mac the last deleted event will be missing.
jozkee commentedon Nov 16, 2020
I see now, it is reporting Create twice and not reporting Delete when you erase the root as you mentioned:
dotnet-policy-service commentedon May 18, 2025
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This process is part of our issue cleanup automation.
dotnet-policy-service commentedon Jun 2, 2025
This issue will now be closed since it had been marked
no-recent-activitybut received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.