ASP.NET CS0016 – Compiler Access Denied

Once in a while, a developer will have one of those unbelievably frustrating problems with his environment or platform that makes him bang his head against the wall for hours.  I’m sure people in other trades have similar experiences somehow, but I don’t know of a good parallel offhand.

I just experienced such a problem with ASP.NET.  I just imported a deployment package of a self-hosted NuGet feed, which is just an empty ASP.NET application built as explained in the NuGet documentation.  Anyway, after importing the deployment package using webdeploy (via the IIS Management Console), I had an application under my default web site called “nuget”.  After that, I kind of expected it to Just Work, at least from the server itself.

 I opened Internet Explorer and navigated to http://localhost/nuget, and got the following nastiness:

Compiler Error Message: CS0016: Could not write to output file ‘c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\62d43c41\27d749ca\App_Code.7lodcznm.dll’

The particular DLL the compiler was trying to write was different than shown, but this is the error.  Well, I found several posts just glibly saying “all you have to do is make sure the ‘Temporary ASP.NET Files’ permissions are set properly”.  It sure sounded easy enough.  Turns out, it was too easy, because it didn’t work.  I ended up giving full control to “Everyone” to kind of prove what was really going on.  After that didn’t work, I ran procmon and filtered carefully to find a non-SUCCESS event on a path including “temp” and by a process called “csc.exe” (the C# compiler).  Sure enough, I found this:

3:01:01.3158251 AM	csc.exe	6428	CreateFile	C:\Windows\Temp\RES3277.tmp	ACCESS DENIED
Desired Access: Generic Read, Disposition: Create, Options: Synchronous IO Non-Alert, Non-Directory File,
Attributes: N, ShareMode: None, AllocationSize: 0

You can see here that the actual error is not what appeared in the browser window, frustratingly. I gave Full Control permissions to the Everyone group on \Windows\Temp, and that seemed to fix it.

Well, that won’t do – it’s not a good idea to do the equivalent of “chmod 777″ on \Windows\Temp, so I needed to give access to just the DefaultAppPool user.  Well, guess what?  When I went through Explorer, I was not able to find the user through the UI to give it permissions.  Ultimately, I figured out that I could do it using icacls:

PS C:\Windows> icacls Temp /t /grant "IIS AppPool\DefaultAppPool:(F)"

After doing the same to the “Temporary ASP.NET Files”  folder, I was done.  Finally.  Now I’ve got a 404 error to fix…

2 Comments

  • manofry
    May 1, 2012 - 12:40 pm | Permalink

    Nice (Y)

  • September 13, 2012 - 11:26 am | Permalink

    this can also happen if you have a bad %TMP% variable. like, one that has a in it.

  • Leave a Reply

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

    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>