Fixing the ASP.NET “CS0016: Could not write to output file” Error

Scott Walker · Dec 22, 2010

After deploying a new ASP.NET 4 application from development to production, you may encounter the dreaded:

CS0016: Could not write to output file

This error almost always indicates a permissions issue. ASP.NET needs access to specific temporary folders when compiling and writing output files. If those folders are missing or restricted, the application will fail to run.

Root Cause

ASP.NET uses the system’s temporary directories (TEMP and TMP) during compilation. If these folders do not exist or the IIS worker process does not have permission to write to them, you will see CS0016.

Microsoft’s recommendation is to ensure the following paths exist and have proper permissions:


%SYSTEMROOT%\TEMP  = TEMP
%SYSTEMROOT%\TEMP  = TMP

On most servers, this resolves to:


C:\WINDOWS\TEMP

Solution

In my case, the C:\WINDOWS\TEMP folder did not exist at all. After creating the folder manually and assigning the correct permissions, the application compiled and ran without errors.

Required Permissions

Add the following accounts to C:\WINDOWS\TEMP with write access:

  • NETWORK SERVICE
  • IIS_IUSRS

These accounts are used by IIS and ASP.NET during runtime. Without write access, ASP.NET cannot generate temporary files needed for compilation.

Why This Works

ASP.NET writes temporary compilation data to the system’s temp directory before placing compiled assemblies into the Framework folders. If the temp directory is missing or locked down, the compilation process fails, resulting in CS0016.

Ensuring the folder exists and granting proper permissions resolves the issue immediately.

This fix should solve most permission-related CS0016 errors on ASP.NET applications running under IIS.

Comments (0)

Please sign in to comment.