Forum Discussion

mellamokb's avatar
mellamokb
Copper Contributor
Sep 26, 2024

appData has randomly disappeared and crashing app

Very weird issue. We store local cache for EF model in

 

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

 

Been doing this for years.  We restarted the app this afternoon, and it suddenly crashed just on restart without any code changes.  In debugging I found that this code is now returning an empty string, so the path to save is invalid.

 

Why did this path suddenly cease to exist, and why on a restart without any actual code deployment?  Is there some documented change to Azure App Services that would explain how to properly retrieve AppData path?

  • mellamokb 

     

    Here are a few potential reasons and solutions.

    Permission Issues- Sometimes, access permissions can change unexpectedly in Azure App Services. It's possible that the app no longer has the necessary permissions to access the ApplicationData folder. Double-check the app's permissions and ensure it still has access to this directory.

     

    Azure App Service Sandbox Limitations- Azure App Services run apps in a restricted environment, and while there may not be any recent major changes, periodic platform updates could affect how certain system folders are accessed. It’s worth checking Azure App Service release notes for any updates that could be related to this issue.

     

    Switch to Temporary Storage- Azure App Services provide full access to the D-\local\Temp directory. Instead of relying on ApplicationData, try using the temp directory for your caching needs-
    string cachePath = Path.GetTempPath();
    This folder is more stable and should work consistently in Azure App Services

     

    Environment-Specific Behavior- Sometimes, changes between different environments (like staging or production) can cause unexpected behavior. Verify that the environment settings haven’t been modified in a way that impacts the retrieval of the Application Data path.

     

    File System Changes After Restart- It's possible the file system gets cleared during an app restart or recycle, which can sometimes happen in Azure App Services. If this is the case, consider using persistent storage like Azure Blob Storage for caching, instead of relying on the local file system.

     

    Store and retrieve settings and other app data Documentation URL: https://learn.microsoft.com/en-us/windows/apps/design/app-settings/store-and-retrieve-app-data

    • mellamokb's avatar
      mellamokb
      Copper Contributor

      balasubramanim 

      Appreciate the response!  Can you point me to the release notes for Azure App Service? That was the first place I tried to look when I encountered this issue, and couldn't find any.

       

      The thing is Application Data still definitely exists, as c:\local\AppData.  Plus %APPDATA% resolves to this path, and so does Environment.GetEnvironmentVariable("APPDATA") and Environment.ExpandEnvironmentVariables("%APPDATA%").  This is what I replaced with to fix the code.  It just seems that for some reason Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) is now not returning a path even though I thought it was essentially the same thing.  And it was unexpected that it could break this way on a user-initiated restart, not a system restart or Azure App Service deployment upgrade.

Resources