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
Improve exception message when trying to open a directory as a file. #100720
If you mistakenly pass a directory as the sourceArchiveFileName parameter for ZipFile.ExtractToDirectory(), you receive an UnauthorizedAccessException.
Based on the current docs, I would assume the exception would be a NotSupportedException or InvalidDataException with a message like "[sourceArchiveFileName] is not a valid zip archive".
Actual behavior
You get an UnauthorizedAccessException with the message "Access to the path '[sourceArchiveFileName]' is denied" regardless of permissions on the directory.
Regression?
.NET 8, 7, & 6
Known Workarounds
No response
Configuration
.NET 8
Windows 11 x64 and mcr.microsoft.com/dotnet/runtime:8.0 Docker image
Perhaps FileStream could just change the Exception.Message of the UnauthorizedAccessException to say that it's a directory, when it gets an EISDIR error from the operating system. Changing the type of the exception seems more risky.
I don't expect we can change the exception type, but perhaps a better error message is possible when a directory path is provided to open. Moving the suggestion to IO.
We're open to suggestions for improving the exception message. Some IO APIs document this behavior e.g. File.Open, some don't (e.g. FileStream.ctors, although it should).
ZipFile.ExtractToDirectory could also lift the exception documentation, so it becomes clear for its users.
changed the title [-]Misleading exception for ZipFile.ExtractToDirectory[/-][+]Improve exception message when trying to open a directory as a file.[/+]on Oct 23, 2025
Activity
dotnet-policy-service commentedon Apr 6, 2024
Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.
[-]Misleading exception for ZipFIle.ExtractToDirectory[/-][+]Misleading exception for ZipFile.ExtractToDirectory[/+]KalleOlaviNiemitalo commentedon Apr 8, 2024
Perhaps FileStream could just change the Exception.Message of the UnauthorizedAccessException to say that it's a directory, when it gets an EISDIR error from the operating system. Changing the type of the exception seems more risky.
ericstj commentedon Jul 24, 2024
I don't expect we can change the exception type, but perhaps a better error message is possible when a directory path is provided to open. Moving the suggestion to IO.
dotnet-policy-service commentedon Jul 24, 2024
Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.
jozkee commentedon Jul 26, 2024
We're open to suggestions for improving the exception message. Some IO APIs document this behavior e.g. File.Open, some don't (e.g. FileStream.ctors, although it should).
ZipFile.ExtractToDirectory could also lift the exception documentation, so it becomes clear for its users.
dotnet-policy-service commentedon Oct 23, 2025
Tagging subscribers to this area: @dotnet/area-system-io-compression
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Oct 23, 2025
Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.
[-]Misleading exception for ZipFile.ExtractToDirectory[/-][+]Improve exception message when trying to open a directory as a file.[/+]Improve exception message when passing directory to ZipFile methods (d…