Default TEMP folder size is too small on a cloud service web/worker role

The default temporary directory of a cloud service worker or web role has a maximum size of 100 MB, which may become full at some point. This article describes how to avoid running out of space for the temporary directory.

If your Azure issue is not addressed in this article, visit the Azure forums on MSDN and Stack Overflow. You can post your issue in these forums, or post to @AzureSupport on Twitter. You also can submit an Azure support request. To submit a support request, on the Azure support page, select Get support.

Why do I run out of space?

The standard Windows environment variables TEMP and TMP are available to code that is running in your application. Both TEMP and TMP point to a single directory that has a maximum size of 100 MB. Any data that is stored in this directory is not persisted across the lifecycle of the cloud service; if the role instances in a cloud service are recycled, the directory is cleaned.

Suggestion to fix the problem

Implement one of the following alternatives:

  • Configure a local storage resource, and access it directly instead of using TEMP or TMP. To access a local storage resource from code that is running within your application, call the RoleEnvironment.GetLocalResource method.
  • Configure a local storage resource, and point the TEMP and TMP directories to point to the path of the local storage resource. This modification should be performed within the RoleEntryPoint.OnStart method.

The following code example shows how to modify the target directories for TEMP and TMP from within the OnStart method:

using System;
using Microsoft.WindowsAzure.ServiceRuntime;

namespace WorkerRole1
    public class WorkerRole : RoleEntryPoint
        public override bool OnStart()
            // The local resource declaration must have been added to the
            // service definition file for the role named WorkerRole1:
            // <LocalResources>
            //    <LocalStorage name="CustomTempLocalStore"
            //                  cleanOnRoleRecycle="false"
            //                  sizeInMB="1024" />
            // </LocalResources>

            string customTempLocalResourcePath =
            Environment.SetEnvironmentVariable("TMP", customTempLocalResourcePath);
            Environment.SetEnvironmentVariable("TEMP", customTempLocalResourcePath);

            // The rest of your startup code goes hereā€¦

            return base.OnStart();

Next steps

Read a blog that describes How to increase the size of the Azure Web Role ASP.NET Temporary Folder.

View more troubleshooting articles for cloud services.

To learn how to troubleshoot cloud service role issues by using Azure PaaS computer diagnostics data, view Kevin Williamson's blog series.