FileNotFoundException when using System.IO.Directory.CreateDirectory()

落花浮王杯 提交于 2019-12-11 02:01:50

问题


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"));

回答1:


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



来源:https://stackoverflow.com/questions/54552147/filenotfoundexception-when-using-system-io-directory-createdirectory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!