Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build error: "The process cannot access the file because it is being used by another process"

I've got a C# webforms app, that until today had been working just swimmingly.

Now today, all of a sudden, every time I try run the app, I get a file locking error:

Unable to copy file "obj\Debug\MyProject.exe" to "bin\Debug\MyProject.exe". The process cannot access the file "bin\Debug\MyProject.exe" because it is being used by another process.

Googling the error doesn't come up with anything beyond the obvious, i.e. VS thinks the file is locked. And it is definitely Visual Studio itself that locks the file, because when I close VS and reopen it, the project executes fine - the first time. When I try to run it a second time, I get the file locking error.

Closing VS and reopening every time I want to run the app is not a viable workaround! How do I find out what's locking the file, and stop it from getting locked?

EDIT: Another interesting discovery: I don't even have to run the app. Just compiling it once causes the file locking; I cannot compile twice in a row!

This problem is specific to one project in my solution. All other projects work fine and can be executed as many times as I like. It's only this one project that gets itself locked up.

like image 518
Shaul Behr Avatar asked Feb 27 '11 15:02

Shaul Behr


People also ask

How do you fix 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.


1 Answers

I have found a simple solution which works for me. It goes like this:

When the problem occurs, just change the building configuration at the top (if in “Release” to “Debug” and vice versa), build and then change back to previous configuration and build again.

screenshot

I suppose that changing the configuration releases the vcshost and devenv.

like image 179
Yechiel B.D. Avatar answered Oct 10 '22 00:10

Yechiel B.D.