Search

Calling File.Delete() on a directory yields a misleading irrelevant exception by Dmitry Me

Resolved
as Won't Fix Help for as Won't Fix

1
0
Sign in
to vote
Type: Bug
ID: 774001
Opened: 12/11/2012 1:38:42 AM
Access Restriction: Public
0
Workaround(s)
0
User(s) can reproduce this bug
If I call System.IO.File.Delete() and pass it a directory path instead of file path I get UnathorizedAccessException with text "Access to the path <path> is denied.". This is seriously misleading because it implies I have some problems with permissions while the real problem is that the path identifies a directory and not a file.

It should be something like an InvalidOperationException and the text should be something like "Path <path> is a directory, file path required."

    
Details (expand)

Visual Studio/Team Foundation Server/.NET Framework Tooling Version

.NET Framework 4.0

Steps to reproduce

Call System.IO.File.Delete() and pass it a directory path instead of file path.

Product Language

English

Operating System

Windows Server 2008 R2

Operating System Language

English

Actual results

UnathorizedAccessException with "Access to the path <path> is denied".

Expected results

A more suitable exception (perhaps InvalidOperationException) with a more relevant text like "Path <path> is a directory, file path required."
File Attachments
0 attachments
Sign in to post a comment.
Posted by Microsoft on 12/11/2012 at 10:12 PM
Thank you for submitting feedback on Visual Studio and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by Microsoft on 12/11/2012 at 1:50 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.