Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VisualStudio2010 Debugging - The process cannot access the file ... because it is being used by another process

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?

like image 372
Richard Forss Avatar asked Apr 22 '10 10:04

Richard Forss


People also ask

How do you fix the process Cannot access the file because it is being used by another process?

Process cannot access file because it is being used by another process error message. To resolve this error: Press Ctrl + Alt + Delete, then click Task Manager. Ensure you're on the Processes tab.

How do you check if a file is being used by another process in Windows C#?

First check if the file exists (File. Exists) if so try to open for write within try and catch block, if exception is generated then it is used by another process.


2 Answers

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.

like image 125
DocKell Avatar answered Sep 20 '22 07:09

DocKell


As of October 2012, I still have that issue so the VS 2010 SP1 didn't solve the problem. What I did, and worked consistently, was disabling the hosting process in the projects.

To disable the hosting process:

.  Open a project in Visual Studio.  .  On the Project menu, click Properties.  .  Click the Debug tab.  .  Clear the Enable the Visual Studio hosting process check box. 

Source: http://msdn.microsoft.com/en-us/library/ms185330(v=vs.100).aspx

like image 26
Alex. S. Avatar answered Sep 20 '22 07:09

Alex. S.