Visual-studio – VisualStudio2010 Debugging – The process cannot access the file … because it is being used by another process

debuggingvisual studiovisual studio 2010

I'm unable to debug a WinForms C# application using the released version of Visual Studio 2010 Prof.

I get the following error message after the second debugging run.

Error 9 Unable to copy file "obj\x86\Debug\Arrowgrass Reports.exe" to "bin\Debug\Arrowgrass Reports.exe". The process cannot access the file 'bin\Debug\Arrowgrass Reports.exe' because it is being used by another process.

I've tried a pre-build script to attempt to delete this file, but it's locked by Visual Studio.

There are a few references to this on the net so it is a know problem. Does anyone have a hotfix or effective work-around?

Best Answer

I have found this issue very easy to reproduce, and the fix for me is a variation on Richard Fors' answer. If I have a UserControl open in the designer, run the debugger, and then edit the UserControl, the subsequent rebuild will fail. If I close the UserControl before running the debugger I never get this error, so I just make sure to close the designer window before hitting F5.