Alex Rivera | Logout

Why do I get "file is used by another process" errors when I debug within Visual Studio?

Asked 2009-11-30T06:04:48.643
33

Using Visual Studio 2010 beta, when I run my application within the IDE for debugging, it works perfectly the first time. However, after closing the debug session, either by closing the application or clicking the stop debugging button, all subsequent attempts to debug the application fail with:

Error 1 Unable to copy file "obj\Debug\Application.dll" to "bin\Debug\Application.dll". The process cannot access the file 'bin\Debug\Application.dll' because it is being used by another process.

Handle.exe from SysInternals does show handles open, but even if I close the handles, the error doesn't go away. Any attempts to delete the file manually result in an "Access Denied" error message.

To fix this, I have to completely restart Visual Studio, afterwhich the Debug session will work once and stop again.

I'm not entirely sure when this started happening, but I'm pretty sure it's fairly recently.

UPDATE: After I force close the handles on Application.dll, I get the following error from VS:

Error 1 Unable to copy file "obj\Debug\Application.dll" to "bin\Debug\Application.dll". The requested operation cannot be performed on a file with a user-mapped section open.

What the heck is a "user-mapped section"??

UPDATE 2: It appears that this problem occurs when I have a Form open in Design view when trying to debug. I'm going to do some more troubleshooting and then post my results.

UPDATE 3: I think I've narrowed it down to a form using a UserControl.

Edit
Report

1 Answer

3

I've seen the Windows Indexing Service cause this. Disabling it helped. Virus scanners can also be at fault. Mutliple Application.Close() calls can supposedly cause this, too.

Of course, since it always works the first time, I suppose these are unlikely.

answered 2009-11-30T06:13:19.827

Your Answer