2

I am facing a problem when running .net app on Azure. When using CreateDirectory method, it throws FileNotFoundException with the message of "Could not find file 'D:\home\site\wwwroot\CVs'.".

The app worked without any exception when running locally and on a private server. Any idea what could be the problem?

Directory.CreateDirectory(Path.Combine(Directory.GetCurrentDirectory(), "CVs"));
TylerH
  • 20,799
  • 66
  • 75
  • 101
Coolerhino
  • 21
  • 3
  • please check this issue -> https://github.com/dotnet/corefx/issues/26561 – cokceken Feb 06 '19 at 11:10
  • 3
    [`Directory.CreateDirectory`](https://learn.microsoft.com/en-us/dotnet/api/system.io.directory.createdirectory?view=netframework-4.7.2) shouldn't throw `FileNotFoundException` – Tim Schmelter Feb 06 '19 at 11:14
  • According to @cokceken this is the way Directory.CreateDirectory throws "UnauthorizedAccess" exceptions. – MarengoHue Feb 06 '19 at 11:18

1 Answers1

2

Assuming, that you're running your app as an Azure Web App, you need to be careful what you try to write to the file system, because of the nature of how the virtual machines of Azure Web Apps are handled.

Since Azure doesn't guarantee the availability of the same VM each time, but only the availability of a VM running your app, this means the file system (beyond the app files you deployed) isn't guaranteed to persist. If your app is scaled, then we're entering a whole new problem of persistence between multiple VMs.

Check the answer to the following question for more details: https://stackoverflow.com/a/12968226/912268

Andor Baranyi
  • 197
  • 1
  • 8
  • There would be no problem about persistence, because it is only to save files for a while just to make zip from then and download it. I'm curious because I have just updated a branch and other builds that depend on the same function doesn't share the same issue – Coolerhino Feb 06 '19 at 12:46
  • If you just want to make a zip file to serve as a download - use the %temp% folder to store it. – MarengoHue Feb 13 '19 at 08:27