views:

969

answers:

2

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?

A: 

You can try to kill the vshost.exe process:

taskkill /F /IM "Arrowgrass Reports.vshosts.exe"

If this doesn't help you might want to follow the tips given here:

File Lock Issue in Visual Studio When Building a Project

0xA3
The link doesn't try to decipher the cause of the problem and thus it works or not. Not it is in my case.
Tomas Pajonk
@Tomas Pajonk: The cause of the problem is most likely the fact stated by the error message; your target is being used by another process. To find out, which process, you can use Process Explorer from Sysinternal; press Ctrl+F and search for "Arrowgrass Reports.exe"
0xA3
Just in case anyone is still interested in this, I've noticed that the problem only occurs when user defined controls are used. It looks like Visual Studio itself is the other process, as it is rendering the control. I found that as long as this control was not on the screen, I didn't get the error.
Richard Forss
+4  A: 

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.

DocKell