Repository navigation
[release/10.0] Handle STATUS_OBJECT_NAME_NOT_FOUND in Windows directory enumeration - #130327
Merged
Merged
Conversation
Add STATUS_OBJECT_NAME_NOT_FOUND (0xC0000034) to the no-matches branch of FileSystemEnumerator<T>.GetData() on Windows, alongside STATUS_FILE_NOT_FOUND. A filtered NtQueryDirectoryFile that matches zero entries can return this status instead of STATUS_NO_SUCH_FILE on some file systems (for example, certain read-only or virtual file systems); it is now treated as an empty result instead of throwing FileNotFoundException. Fixes #130134 Co-authored-by: Copilot <[email protected]>
Contributor
|
Tagging subscribers to this area: @dotnet/area-system-io |
jeffhandley
approved these changes
Jul 8, 2026
tannergooding
approved these changes
Jul 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #130196 to release/10.0
/cc @jeffhandley @stephentoub @JeremyKuhne
Customer Impact
Reported in #130134. The failure requires all of these conditions:
WEBSITE_RUN_FROM_PACKAGE, so the content root is a read-only, zip-mounted virtual file system rather than a physical directory.Directory.GetFiles/Directory.EnumerateFiles(or theDirectoryInfo/Directory.GetFileSystemEntriesvariants) against that directory.Under those conditions the call throws
System.IO.FileNotFoundException, naming the directory itself as the missing file, instead of returning an empty result. The directory exists and is enumerable -- a pattern that does match returns results normally; only the zero-match case fails.In the customer's app this aborted host startup: a third-party library's
Directory.GetFiles(appBaseDir, "Ninject.*.dll")probe running duringIHostedLifecycleService.StartingAsyncthrew, preventing the app from starting after the App Service instance rolled forward to 10.0.9.There is no straightforward workaround: whether the directory's driver reports the unhandled status is outside the app's control, and framework-dependent App Service apps automatically roll forward to the latest installed patch, so pinning back to 10.0.8 is not a durable option.
Regression
Introduced in 10.0.9 by #127974 (backport of #122947 / #123695), which began passing the search pattern to
NtQueryDirectoryFileas an OS-levelFileNamefilter. When zero entries match,FileSystemEnumerator<T>.GetData()handled onlySTATUS_NO_SUCH_FILE(0xC000000F); the affected drivers report the same "no matching entries" condition asSTATUS_OBJECT_NAME_NOT_FOUND(0xC0000034), which fell through to thedefaultarm and threw. Pinning the runtime to 10.0.7 or 10.0.8 returns an empty result.Testing
Reproducing this requires a file system driver that returns
0xC0000034for a zero-match filteredNtQueryDirectoryFile; the built-in drivers (NTFS, ReFS, UDF, CDFS) all return the already-handled0xC000000F, so there is no in-repo regression test -- which is also why the original change missed it. The fix was validated out-of-band by hookingntdll!NtQueryDirectoryFilein-process to rewrite the zero-match status0xC000000F->0xC0000034for a single directory, faithfully mirroring the reported driver behavior:Directory.GetFiles(dir, "__no_such_file__*.dll")probe throws on the shipped 10.0.9 runtime and on an unmodified build of this branch, and returns an empty array with this fix, while a matching pattern (*.dll) continues to return results in all cases.dotnet-installed 10.0.7 / 10.0.8 (return empty; pre-regression), 10.0.9 (throws), and this branch (throws without the fix, empty with it) on both x64 and Arm64.System.IO.FileSystem.Testsshows no regressions from this change.Risk
Low. The change adds a single
case(STATUS_OBJECT_NAME_NOT_FOUND) to the existing no-matches branch ofGetData()on Windows, alongsideSTATUS_FILE_NOT_FOUND, with no other control-flow changes. The directory handle was already opened successfully inInit(), so this status can only mean the filter matched nothing -- consistent with the siblingSTATUS_FILE_NOT_FOUND/STATUS_OBJECT_NAME_INVALIDstatuses already handled there.The most notable risk is that the fix is incomplete -- that another status could surface the same symptom in a scenario not yet observed. This was measured against the Win32 error-code mapping: the reported exception is
FileNotFoundException/ "Could not find file", whichWin32Marshal.GetExceptionForWin32Errorproduces only fromERROR_FILE_NOT_FOUND(2), and only twoNTSTATUSvalues map toERROR_FILE_NOT_FOUNDviaRtlNtStatusToDosError--STATUS_NO_SUCH_FILE(already handled) andSTATUS_OBJECT_NAME_NOT_FOUND(this fix). No other Win32 error code is applicable, so no additional status can reproduce the reported failure through this path.The alternative to this fix would be to revert the backport (#127974) and return to the prior implementation, which did not carry the gains of the original changes (#122947 / #123695). Those changes resolved a long-standing performance problem (issue #56464): on Windows,
Directory.GetFiles/Directory.EnumerateFileswith a selective pattern in a large directory was O(N) instead of O(log N), because .NET always passednullas theNtQueryDirectoryFileFileNamefilter and enumerated every entry before filtering in managed code. For example,Directory.GetFiles(path, "A14881*.jpg")in a directory of 140K files with 4 matches enumerated all 140K entries; the optimization reduces that to ~4-10 entries by using the OS filter as a pre-filter, while the managed filter still validates every result. This was reported repeatedly by internal and external customers -- including PowerShell -- who experience it as a regression when migrating from .NET Framework to .NET 10. Reverting would reintroduce those bottlenecks broadly in order to avoid a throw that occurs only on the narrow set of file system drivers that report zero matches as0xC0000034; adding the single status case preserves the performance win while resolving the regression.Note
This pull request description was authored with assistance from GitHub Copilot.