access denied to DLLs on first login attempt

Hi, I hope you can help me with this irritating, time-consuming problem.

My company has been given a legacy ASP.NET website to maintain.

There is an irritating 'feature' every time we make a change to the code in Visual Studio, Build/Rebuild and test locally on our PCs: When we enter our login details on the homepage it just refreshes itself. On the second attempt it logs in ok.

Putting it in Debug shows that the problem is:
"A first chance exception of type 'System.UnauthorizedAccessException' occurred in mscorlib.dll
"Additional information: Access to the path "SuchAndSuch.dll" is denied."

There are about 50 such messages for the various referenced DLLs. The DLLs live in the usual /bin folder under the application's virtual directories (there are two). In between all those messages there is an occasional:

"A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
"Additional information: The directory is not empty."

And at the end one of these:
"A first chance exception of type 'System.Web.HttpCompileException' occurred in system.web.dll
"Additional information: External component has thrown an exception."

Followed by four of these:
"A first chance exception of type 'System.Web.HttpException' occurred in system.web.dll
"Additional information: External component has thrown an exception."

The problem doesn't occur if we IISRESET after each change. But it is tiresome to have to do this too.

I'm using Windows XP Professional. .NET Framework 1.1 only.

We have these lines in the web.config:
<authentication mode="Windows"/>
<identity impersonate="true"/>

The virtual directories' settings are Read/Write, Low Application Protection, Anonymous access (to user <machine_name>\IUSR_<machine_name>).

After looking on various forums I have unsuccessfully tried:

1. Giving Full Control access on C:\inetpub\wwwroot to the users:
<network_name>\ASPNET
ANONYMOUS LOGON
<machine_name>\IUSR_<machine_name>
NETWORK SERVICE

2. Disabling the Indexing Service.
(NB. Before I did this, after every code change I'd get an error page on bringing up the homepage, or logging in, and would have to do another complete Rebuild after which I might be able to log in - on the second attempt. Or sometimes I had to close Visual Studio and reopen it to be able to log in to the app).

3. Removing <identity impersonate="true"/> from the web.config and unchecking Anonymous access on the virtual directory. Then resetting IIS, clearing cache, and rebuilding.

The problem doesn't occur when we deploy to our test box, which we do simply by copying our virtual directories to it (no IISRESET). It is running Windows Server 2003. The IIS settings and folder security are the same as my PC. This all leads me to believe that it is Visual Studio that is locking the /bin files on my PC. But the lock seems to be released by the first login attempt, which doesn't make any sense. I have looked at the security settings on one of the DLLs before and after the first login attempt and they do not change.

I am hoping that if I find a fix for this, I can also re-enable Indexing without the errors that causes, and then I can roll-out an acceptable, sensible, satisfactory solution to all the other developers (!), which will save everyone a few minutes every hour - and as you know, it all adds up. Plus our tempers will improve. :)

Thank you guys.
[3751 byte] By [hobbes_child] at [2007-11-20 11:39:40]