Application startup exception Exception: System.IO.FileNotFoundException

After setting up an Azure App Service recently, I got the following error when trying to browse. The fix was simple but not obvious.

Application startup exception Exception: System.IO.FileNotFoundException: Could not find file 'D:\home\site\wwwroot\obj'
System.IO.FileSystem.CreateDirectory(String fullPath, Byte[] securityDescriptor)

This came about because the application tried to write to the Azure App Service’s file system at startup. Although the error says “Could not find file”, (a slightly odd response to a CreateDirectory instruction, no?), it’s actually a permissions issue.

There could be various reasons an application needs to write to the filesystem and therefore see this error, but as a quick bit of background, in my case this application was running .NET Core Identity, and because it was a non-production instance behind a firewall, it was in development mode. Turns out that in this mode, a development key is created at startup (but obviously not if there’s no permission).

So how do we start with a pretty straightforward deployment through an Azure DevOps pipeline to an App Service, and somehow end up without the right file system permissions? The cigar goes to my good friend Tomáš Herceg (he’s not really my friend, I’ve never heard of him, but he’s a guy from the internet who knows his stuff).

In this article, he explains that it’s an issue with the Azure App service deploy task in Azure Devops. He goes into more detail than I will here, but basically the fix is that you have to tick “Select deployment method” under Additional Deployment Options and make sure the “Deployment method” is set to “Web Deploy”:

Tomáš mentions having to change that Deployment method, but even stranger for me, the method was already “Web Deploy”, as soon as I ticked “Select deployment method”.

So for me, just the action of ticking “Select deployment method” and re-deploying from the pipeline solved the issue.

Published
Categorised as Azure

One comment

  1. Many thanks for your article, got the same problem with an application deployed on Azure App Services (Duende Identity Server) and once you try to run it with an deployed as default task in a release pipeline, you got that kind of problem…

    Althought it seems to be related to the sandboxed environment in which App Services put your web app in, this fixed my problem and the Identity Server is now running.

    Thanks !

Leave a comment

Your email address will not be published. Required fields are marked *