runtime: Directory.CreateDirectory throwing wrong exception

Hi,

When trying to create a new directory (or file) from my ASP.NET Core app to a location I do not necessarily have access to, I get a FileNotFoundException with the following message:

Could not find file 'D:\Users\Shimmy\Documents\Visual Studio 2017\Projects\MyProject\Api\FilesVault\1afb42e2-f160-4f6d-9eab-a82ca3cbf076'.

Here’s my code:

if (!Directory.Exists(path))
{
  try
  {
    Directory.CreateDirectory(path);
  }
  catch (FileNotFoundException)
  {//breakpoint - debugger breaks here
    //No documentation of FileNotFoundException to be thrown from that method.
  }
}

In addition, the following message pops up in the Windows 10 notification center:

image

I understand I don’t have proper access to that folder, I’m just here to wonder out why it’s FileNotFoundException rather than one of the documented types.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 21 (19 by maintainers)

Most upvoted comments

Ping @weitzhandler we would like to fix this if it is a bug.

This is wrong. In general the code tries to convert ERROR_FILE_NOT_FOUND to ERROR_PATH_NOT_FOUND etc. @Anipik can you see where this is getting thrown from.