Reconsider the exception type thrown when trying to open a directory as file
#70.275 geöffnet am 6. Juni 2022
Repository-Metriken
- Stars
- (17.886 Stars)
- PR-Merge-Metriken
- (Durchschn. Merge 12T 11h) (661 gemergte PRs in 30 T)
Beschreibung
In FileSystem.Windows, as well as SafeFileHandle.Windows we have this comment:
However, when testing with native code on Windows 10, calling CreateFileA returns ERROR_PATH_NOT_FOUND for either C:\ or other normal directories.
So this causing behavior inconsistency on managed API again: when calling File.Open on C:\, it throws UnauthorizedException. When calling with other directories, it throws PathNotFoundException.
I didn't find any test for exceptions in System.IO.FileSystem.
Changing the exception thrown is technically breaking, but helps for consistency. Changing to an exception is already used for other circumstances won't break much.
We need to also examine Windows 7 and 8 behavior and the behavior of CreateFile2 and NtCreateFile. (Or if you can directly check it through Windows source code)