Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 517
Chris Thompson Avatar asked Nov 30 '09 06:11

Chris Thompson


People also ask

How do I Debug multiple processes in Visual Studio?

To change the startup project, in Solution Explorer, right-click a different project and select Set as StartUp Project. To start debugging a project from Solution Explorer without making it the startup project, right-click the project and select Debug > Start new instance or Step into new instance.


2 Answers

To be honest with you, it sounds like a bug in VS2010. For some reason it isn't closing the open handles when the debugger stops. Killing the VS process automatically closes those handles, allowing you to access the file again. As a work around, you might look at unlocker it's free and works exceptionally well. I know that's not a great answer, but it should be faster than restarting VS. You might to consider sending a bug report too...

Unlocker doesn't work on 64-bit OS, LockHunter does though.

like image 93
Chris Thompson Avatar answered Sep 18 '22 09:09

Chris Thompson


Here is how I solved this problem

*I open the project Properties, *select the build tab, *Clear the output path, *and buid(this will create the dll in the root folder) *come back to the output path and select browse(browse to the bin directory to either debug/release)and voila!

like image 39
samurab Avatar answered Sep 19 '22 09:09

samurab